Matlab:在同一轴上绘制2和4个三维高斯

Matlab:在同一轴上绘制2和4个三维高斯,matlab,gaussian,surf,Matlab,Gaussian,Surf,使用此代码: 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

使用此代码:

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
我可以绘制单个三维高斯曲线:

我现在要策划

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')
其结果是:


从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
复制
X
Y
矩阵:

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)
,等等。

诀窍就是简单地使用
repmat
复制你的
X
Y
矩阵:

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)
,等等。

子批次?这就是你想要的道歉的可能副本,不够精确-我希望在同一轴线上绘制多个,而不是多个。在澄清之后,我将不再认为这是一个重复的链接问题。这就是你想要的道歉的可能副本,不够精确-我希望在同一轴线上绘制多个,而不是多个。在澄清之后,我将不再考虑这是一个连带问题的复制品。我认为这是你需要的,否则尝试在1个图表中绘制多行:<代码>情节(x,y1,x,y2)< /代码>谢谢你的回答和道歉是不精确的。如果有意义的话,不要绘制多个图?我认为这是您需要的,否则请尝试在一个图中绘制多条线:
绘图(x,y1,x,y2)
感谢您的回答,并为不精确表示歉意-我基本上是在同一个图上绘制多个高斯数,而不是多个情节,如果这有意义的话?这正是我想要的。非常感谢你!我想它可以通过复制
z
而不是
X
Y
来稍微优化一下,但总体来说非常好!这正是我想要的。非常感谢你!我想它可以通过复制
z
而不是
X
Y
来稍微优化一下,但总体来说非常好!