Only plot the contour that satisfies a condition
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/249574/image.jpeg)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/249575/image.jpeg)
This is what I would sort of expect, a third curve which is in black.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/249576/image.jpeg)
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Contour Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!