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!