[英]Matlab contour plot from contourc data
如何在 Matlab 中,从诸如 countourc 生成的轮廓数据中生成轮廓countourc
? contour
在内部使用contourc
将高程数据转换为等高线数据; 但从文档中看我如何能够简单地直接提供轮廓数据并不明显。
如果您有旧版本的 MATLAB,请尝试此操作
[C,h] = contour(peaks(30),-8:2:8);
h1 = get(h,'children');
X = get(h1,'xdata');
Y = get(h1,'ydata');
hold on
plot(X{5},Y{5},'.r')
hold off
这是 2014 年及更新的
[C,h] = contour(peaks(30),-8:2:8);
i = 1;
slev = 4; % draw specific level
hold on
while i < size(C,2)
ncnt = C(2,i); % number of points for current contour
if abs(C(1,i) - slev) < 0.01 % check if it's desired contour
icnt = i+(1:ncnt);
plot(C(1,icnt), C(2,icnt), '.r')
break;
end
i = i + ncnt + 1; % next contour
end
hold off
如果您有许多等高线,并且想要 plot所有具有相同线属性的曲线,您可以使用以下 function:
function h = contourC(C, varargin)
i = 1;
D = [C.' zeros(size(C, 2), 1)];
while (i < size(C,2))
lvlv = C(1, i); % level value
ncnt = C(2, i); % number of points for current contour
D(i:i+ncnt, 3) = lvlv;
D(i, :) = NaN;
i = i + ncnt + 1; % next contour
end
h = plot3(D(:, 1), D(:, 2), D(:, 3), varargin{:});
end
解析ContourMatrix
( C
)是从阴影的答案中借用的,但它对我的数据执行速度快 30 倍,因为它只调用plot
/ plot3
一次。 此 function 在其实际水平上绘制每条曲线,但是,您可以省略D(:, 3)
并调用plot
以获得平坦轮廓。 像这样使用:
C = contourc(data, ...);
h = contourC(C, '-k', 'linewidth', 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.