2010-05-06 30 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