coordinates of pixels in a contour plot
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all, I drew 2 contour plots of 2 different matrix in the same figure using contour(Z,v) function. At few points they intersect each other, I want the coordinates of those points numerically without using data cursor because I need locations of many of these points and that is several times so I need to use some function or program to find these points. Please Help me
figure; hold on c1=contour(Am1_r,[0 0],'r'); c2=contour(Am1_i,[0 0],'b'); hold off % Am1_r and Am1_i are 51x51 matrix
0 commentaires
Réponses (1)
Jarrod Rivituso
le 23 Fév 2012
I would just bypass the contour altogether. It seems that you essentially want to find the points where
(Am1_r == 0) & (Am2_r == 0)
A little fancy logical indexing would allow you to do this without any contour plot needed. First, two things to note
1. You should probably interpolate your data a bit - 51-by-51 seems rather coarse. interp2 will help you to do this
2. Comparing to zero (as I've shown above) is not always the best idea. Typically you want to make your condition such that the magnitude is less than some threshold.
Here's a quick example for ya...
%Fake data
x = linspace(-1,1,51);
y = linspace(-1,1,51);
[X,Y] = meshgrid(x,y);
Z1 = X.^2 + Y.^2 - 0.5;
Z2 = (X + Y)/2;
%Maybe interpolate your data a bit to make it more fine grained (51 points
%seems kinda low)
xnew = linspace(-1,1,1000);
ynew = linspace(-1,1,1000);
[XNew,YNew] = meshgrid(xnew,ynew);
Z1 = interp2(X,Y,Z1,XNew,YNew);
Z2 = interp2(X,Y,Z2,XNew,YNew);
%Find areas where both matrices are close to zero
threshold = 1e-3;
z1NearZero = abs(Z1) < threshold;
z2NearZero = abs(Z2) < threshold;
allConditionsMet = z1NearZero & z2NearZero;
%Extract x,y data where true
xpoints = XNew(allConditionsMet);
ypoints = YNew(allConditionsMet);
result = [xpoints,ypoints]
%Extract row,column values where true
[r,c] = find(allConditionsMet)
Note that I have defined an x and y scale, which you would probably find helpful to do as well.
Hope this helps!
0 commentaires
Voir également
Catégories
En savoir plus sur Contour Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!