开发者

Subplots of multidimensional arrays in Matlab

I have a 10x10x10 array, z. How do I plot everything in the SAME window so that I would have the 3 plots for z(:,:,1) and below it the three plots for z(:,:,2) etc.?

This is what I have so far:

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 开发者_如何学JAVAnew array called "new2"...

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

end;


I think the first two subplots are supposed to be subplot(1,3,1) and subplot(1,3,2). Also, try inserting hold on after each subplot command --- this should allow you to keep whatever has been plotted before.

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;


What is new1 and new2? Are they the same for all rows? Or also 3D arrays?

I think you need something like this:

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

Or more generally for variable size of 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜