With this code:
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
I can plot a single 3d gaussian:
I now want to plot
1) 2 of these side by side within the same axes
2) 4 of these in two rows of two within the same axes
So basically I want a single 3d plot with multiple gaussians on it. Rather than multiple plots of individual Gaussians if that makes sense
...I know this is probably fairly simple, but im stumped. Any help much appreciated.
This was edited to clarify that I want more than one on the same plot, rather than multiple subplots
A crappy mockup of the 2 gaussian version would look like this:
The trick is simply to replicate your X
and Y
matrices using repmat
:
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
For two Gaussians in the same surface, use X = repmat(X, 2, 1)
, or for more, repmat(X, n, k)
, etc.