contourc - plotting contour matrix
显示 更早的评论
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
采纳的回答
更多回答(1 个)
Liviu Ivanescu
2018-8-18
编辑:Liviu Ivanescu
2018-8-18
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 个评论
Nikola Stan
2021-1-26
编辑:Nikola Stan
2021-1-26
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
2021-9-2
in the first line did you mean "cntr = contourc(matrix,[-2 -2]);"?
i think you forget the "r" in cntr
thanks
Liviu Ivanescu
2021-9-2
you are correct
类别
在 帮助中心 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!