Matlab:在同一轴上绘制 2 和 4 个 3d 高斯

Matlab: plot 2 and 4 3d gaussians on same axes

使用此代码:

x=linspace(-3,3,25);
y=x';               
[X,Y]=meshgrid(x,y);
z=exp(-(X.^2+Y.^2)/2);
h=surf(x,y,z);shading interp
%colormap(col4);
set(h,'LineStyle', '-','LineWidth',0.001,'EdgeColor','k');
set(gca, 'YTick',[],'XTick',[],'ZTick',[]);
box on

我可以绘制单个 3d 高斯:

我现在想画图

1) 其中 2 个并排在同一轴内

2) 其中 4 个在同一轴内两排两排

所以基本上我想要一个带有多个高斯分布的 3d 图。如果有意义的话,而不是单个高斯分布的多个图

...我知道这可能相当简单,但我很难过。非常感谢任何帮助。

编辑此内容是为了澄清我想要在同一个地块上有多个,而不是多个子地块

2 高斯版本的蹩脚模型如下所示:

从 matlab 文档中,一个子图示例似乎正是您所需要的,正如@Ander 所建议的:

x = 0:0.1:10;
y1 = sin(2*x);
y2 = cos(2*x);

figure
subplot(2,2,1)       % add first plot in 2 x 2 grid
plot(x,y1)           % line plot
title('Subplot 1')

subplot(2,2,2)       % add second plot in 2 x 2 grid
scatter(x,y2)        % scatter plot
title('Subplot 2')

subplot(2,2,3)       % add third plot in 2 x 2 grid
stem(x,y1)           % stem plot
title('Subplot 3')

subplot(2,2,4)       % add fourth plot in 2 x 2 grid
yyaxis left          % plot against left y-axis
plot(x,y1)
yyaxis right         % plot against right y-axis
plot(x,y2)
title('Subplot 4')

这导致:

诀窍就是使用 repmat:

复制您的 XY 矩阵
x=linspace(-3,3,25);
y=x';               
[X,Y]=meshgrid(x,y);

X = repmat(X, 2, 2);
Y = repmat(Y, 2, 2);

z=exp(-(X.^2+Y.^2)/2);

% note I'm using a different X and Y now in the call to surf()
h=surf(1:size(z,1),1:size(z,2),z);

shading interp
%colormap(col4);
set(h,'LineStyle', '-','LineWidth',0.001,'EdgeColor','k');
set(gca, 'YTick',[],'XTick',[],'ZTick',[]);
box on

对于同一曲面中的两个高斯,使用X = repmat(X, 2, 1),或者更多,repmat(X, n, k),等等