contourc - plotting contour matrix
Show older comments
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
Accepted Answer
More Answers (1)
Liviu Ivanescu
on 18 Aug 2018
Edited: Liviu Ivanescu
on 18 Aug 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 Comments
Nikola Stan
on 26 Jan 2021
Edited: Nikola Stan
on 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
on 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
on 2 Sep 2021
you are correct
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!