contourc - plotting contour matrix
Afficher commentaires plus anciens
I would like to find the contours, manipulate them, and then plot them.
This plots contours
x = 0:0.1:1; y = 0:0.1:1;
[X,Y] = meshgrid(x,y);
Z = sin(X).*cos(Y);
[con_mat, h] = contour(x, y, Z);
To get the contour information without plotting, can use contourc.
con_mat = contourc(x, y, Z);
However, there appears to be no built-in way to plot this "contour matrix".
Any thoughts?
John
Réponse acceptée
Plus de réponses (1)
Liviu Ivanescu
le 18 Août 2018
Modifié(e) : Liviu Ivanescu
le 18 Août 2018
Here is a way to plot contourc data containing several contours of the same value.
cnt = contourc(matrix,[-2 -2]);
szc = size(cnt);
idz = 1;
while idz<szc(2)
izi = cnt(2,idz);
cnt(2,idz) = nan;
idz = idz+izi+1;
end
plot(cnt(1,:),cnt(2,:))
3 commentaires
Nikola Stan
le 26 Jan 2021
Modifié(e) : Nikola Stan
le 26 Jan 2021
your example was useful to me. I added some code that allows it to keep different isolines separate, which is what I needed:
cnt = contourc(matrix,[-2 -2]);
szc = size(cntr);
idz = 1;
contourNo = 1;
while idz<szc(2)
izi = cntr(2,idz);
cntr(2,idz) = nan;
contourXY{contourNo} = cntr(:,idz+1:idz+izi);
idz = idz+izi+1;
contourNo = contourNo+1;
end
figure()
hold on
for k = 1:contourNo-1
plot(contourXY{k}(1,:), contourXY{k}(2,:));
end
Eduardo Vicente Wolf Trentini
le 2 Sep 2021
in the first line did you mean "cntr = contourc(matrix,[-2 -2]);"?
i think you forget the "r" in cntr
thanks
Liviu Ivanescu
le 2 Sep 2021
you are correct
Catégories
En savoir plus sur Contour Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!