2010-05-06 49 views
0

我有一个10x10x10阵列,z。我如何在SAME窗口中绘制所有的东西,这样我就可以得到z(:,:,1)的3个地块,在它下面的z(:,:,2)等三个地块。Matlab中的多维数组的子阵列

这是我到目前为止有:

for i = 1:10 

z=z(:,:,i); 
figure(i) 
subplot(1,2,1) 
surf(z) 

%code, obtain new array called "new1"... 

subplot(1,2,2) 
surf(new1) 

%code, obtain new array called "new2"... 

subplot(1,3,3) 
surf(new2) 

end; 

回答

2

我觉得前两个次要情节应该是subplot(1,3,1)subplot(1,3,2)。此外,尝试在每个subplot命令后插入hold on ---这应该允许您保留之前绘制的任何内容。

for i = 1:10 

z=z(:,:,i); 
figure(i) 
subplot(1,3,1) 
hold on; 
surf(z) 

%code, obtain new array called "new1"... 

subplot(1,3,2) 
hold on; 
surf(new1) 

%code, obtain new array called "new2"... 

subplot(1,3,3) 
hold on; 
surf(new2) 

end; 
+0

我不认为保持在这种情况下,必要的 - 绘制在不同的子图将不会覆盖先前的子图。但是如果在每个子图中绘制了多于一个的曲面,那就是了。仍然是+1来捕捉错误。 – Kena 2010-05-06 19:38:12

1

什么是new1new2?它们对于所有行都是一样的吗?还是3D数组?

我想你需要的东西是这样的:

for i = 1:10 
    subplot(10*3,3,(i-1)*3+1) 
    surf(z(:,:,i)) 
    subplot(10*3,3,(i-1)*3+2) 
    surf(new1) 
    subplot(10*3,3,(i-1)*3+3) 
    surf(new2) 

end 

或者更一般针对z的可变大小:

N = size(z,3); 
for i = 1:N 
    subplot(N*3,3,(i-1)*3+1) 
    surf(z(:,:,i)) 
    subplot(N*3,3,(i-1)*3+2) 
    surf(new1) 
    subplot(N*3,3,(i-1)*3+3) 
    surf(new2) 

end