필터 지우기
필터 지우기

Only plot the contour that satisfies a condition

조회 수: 6 (최근 30일)
Örs Istok
Örs Istok 2019년 11월 22일
편집: Örs Istok 2019년 11월 22일
Hi all,
I am sorry if a similar question was asked elsewhere but I couldn't find anything on this so far. So let me describe you my problem and what I've tried so far.
I am using FEMM to solve a magnetic problem. I extract a region of interest from the solved problem in this format x,y,B1,B2; where x are the radial coordinates. B1 is the magnetic field along x, y is the longitudinal coordinate and B2 is the field along y. I then import this data and reshape the array so it matches the shape of the region of interest. I then calculate |B| and then calculate the frequency from |B|. for a 2x8 inch surface I got an array of a size 200x800. Then I plot the contour for the entire range of frequencies. Which is around Z=4 inches and r = 0
I am observing which area is the most homogenous and then asign an approximate value for this frequency. Then I am looking for values that are +/- 0.005 this frequency by using the find function. After I get the x,y coordinates for these frequencies I use these indexes and place them into another array with columns x, y, freq. Then plot r against Z and get this. It's great but I am not seeing the line at higher r values.
This is what I would sort of expect, a third curve which is in black.
What I tried is to get the condition for freq +/- 0.005 and whichever value does not satisfy this condition to set all the values to 0. This gives me funny things.
Now enough of this let me add in some code.
p = 5/1e3; % precision
z_ref = 2; % reference position
freq = 2.62% frequency in the homogenous region
%importing data
data_import=csvread([imp_datapath + filename1]);
rscale_org = data_import(:,1);
zscale_org = data_import(:,2);
B1(:,1) = data_import(:,3);
B2(:,1) = data_import(:,4);
%calculating B modulo
B = sqrt(B1.^2+B2.^2);
%info about the area of interest
x1 = 0; x2 = 2; dx =0.01;
y1 = 2; y2 = 10; dy=0.01;
ni = (x2-x1)/dx;
nj = (y2-y1)/dy;
%reshaping data
Bgrid = reshape(B, ni, nj)';
rscale_1 = reshape(rscale_org ,ni, nj);
zscale_1 = reshape(zscale_org, ni, nj);
rscale(1,:) = rscale_1(:,1);
rscale_min = rscale .*-1;
zscale = zscale_1(1,:);
zscale_r(1,:) = zscale(1,:) - z_ref;
%calculating frequency from |B|
Fgrid = Bgrid .* 42.576;
%first plot as shown above
figure(1)
contour(rscale,zscale_r,Fgrid,linspace(1, 10, 100))
hold on
contour(rscale_min,zscale_r,Fgrid,linspace(1, 10, 100))
hold off
xlabel('R, [inch]');
ylabel('Z, [inch]');
title('NMR frequency, symmetric about R = 0');
colormap([0 0 0])
axis equal
axis([-2 2 0 8])
[z_direction, r_direction] = find((Fgrid<=(freq+p))&(Fgrid>=(freq-p)));
n = size(z_direction);
for i = 1 : n(1,1)
%grid_c format [r z freq]
grid_c(i,1) = rscale(1,r_direction(i,1));
grid_c(i,2) = zscale_r(1,z_direction(i,1));
grid_c(i,3) = Fgrid(z_direction(i,1),r_direction(i,1));
end
%the second plot as shown above
figure(2)
plot(grid_c(:,1),grid_c(:,2), 'b*')
xlabel('R, [inch]');
ylabel('Z, [inch]');
for i = 1 : nj
for j = 1 : ni
if ((Fgrid(i,j)>freq-p)&(Fgrid(i,j)<freq+p))
FfFF(i,j)=Fgrid(i,j);
else
FfFF(i,j)=0;
end
end
end
%this plot only shows contours where there are continuous lines
figure(3)
contour(rscale,zscale_r,FfFF,linspace(freq+p,freq-p,10))
hold on
contour(rscale_min,zscale_r,FfFF,linspace(freq+p,freq-p,10))
hold off
xlabel('R, [inch]');
ylabel('Z, [inch]');
title('NMR frequency, symmetric about R = 0');
colormap([0 0 0])
axis equal
axis([-2 2 0 8])
So my question is. Does anyone have an ideea how I could get a contour plot similar to the one I showed you above with the black line on it?
Thanks in advance!
Best wishes,
Ors.
P.S.: I edited the post and I uploaded the data2.csv which contains the data. Maybe it helps.
  댓글 수: 2
darova
darova 2019년 11월 22일
It's not clear for me: what black line represents? Where does it come from?
Örs Istok
Örs Istok 2019년 11월 22일
Thanks for your time Darova.
I tought I missed something :). if you look in the first image, there are 3 lines that contour the middle area. two at the top and bottom and one on the right side. I am only seeing in the second plot the top and bottom lines but not the line on the right. That is why I made the third picture where I drew in the third line that I wish to see. Does this answer your question? :)
Is it possible that the find function doesn't save the indexes for these values?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by