在 MATLAB 中使用 surf 创建沿 z 轴堆叠的二维矩阵

问题描述 投票:0回答:2

下图只是一个带有surf的2d数组的表示。我想创建一个类似的图形,其中 10 个二维数组彼此堆叠,沿 z 轴有某种偏移。

figure();
surf(X);
colormap(hsv);
shading interp;
campos([-70 -150 80]);
grid on;
set(gcf,'color','w');

matlab graphics matlab-figure
2个回答
3
投票

只需使用

surf
多次调用
hold on
,应用逐渐增加的偏移量。

通过default

surf
的1输入版本),偏移量将影响每个表面显示的颜色。这是一个包含三个二维数组的示例。请注意,每一个的峰峰值幅度都不同。

x{1} = .2*peaks(30);
x{2} = .4*peaks(30);
x{3} = .8*peaks(30); % cell array containing three 2D arrays
offset = 7; % desired offset
hold on
for k = 1:numel(x)
    surf(x{k} + offset*(k-1))
end
campos([-100 -170 90])
grid on

为了防止偏移影响颜色,即实现所有表面的颜色一致,请使用 2 或 4 输入版本的

surf
分别指定高度和颜色:

x{1} = .2*peaks(30);
x{2} = .4*peaks(30);
x{3} = .8*peaks(30);
offset = 7;
hold on
for k = 1:numel(x)
    surf(x{k} + offset*(k-1), x{k}) % Only this line has been changed
end
campos([-100 -170 90])
grid on

要根据值生成颜色堆叠平面(无高度变化):按如下方式修改输入参数:

x{1} = .2*peaks(30);
x{2} = .4*peaks(30);
x{3} = .8*peaks(30);
offset = 7;
hold on
for k = 1:numel(x)
    surf(repmat(offset*(k-1), size(x{k})), x{k}) % Only this line has been changed
end
campos([-100 -170 90])
grid on


0
投票

是否可以使用 React 制作这些类型的图表?

© www.soinside.com 2019 - 2024. All rights reserved.