Main Content

突出显示特定等高线层级

此示例演示如何突出显示特定层级的等高线。

Z 定义为从 peaks 函数返回的矩阵。

Z = peaks(100);

Z 中的最小和最大数据值四舍五入取整,并分别将这些值存储到 zminzmax 中。将 zlevs 定义为 40 个介于 zminzmax 之间的值。

zmin = floor(min(Z(:))); 
zmax = ceil(max(Z(:)));
zinc = (zmax - zmin) / 40;
zlevs = zmin:zinc:zmax;

绘制等高线图。

figure
contour(Z,zlevs)

Figure contains an axes object. The axes object contains an object of type contour.

zindex 定义为 zminzmax 之间索引值为 2 的整数值向量。

zindex = zmin:2:zmax;

保留之前的等高线图。创建第二个等高线图并使用 zindex 每隔一个整数值突出显示等高线。将线宽设置为 2。

hold on
contour(Z,zindex,'LineWidth',2)
hold off

Figure contains an axes object. The axes object contains 2 objects of type contour.

另请参阅

| | | | |