【问题标题】:Subplots of multidimensional arrays in MatlabMatlab中多维数组的子图
【发布时间】:2010-05-06 10:04:36
【问题描述】:

我有一个 10x10x10 数组,z。如何在 SAME 窗口中绘制所有内容,以便获得 z(:,:,1) 的 3 个图,以及 z(:,:,2) 等的三个图?

这是我目前所拥有的:

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;

【问题讨论】:

    标签: matlab multidimensional-array


    【解决方案1】:

    我认为前两个子图应该是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;
    

    【讨论】:

    • 我认为在这种情况下不需要保留 - 在不同的子图中绘制不会覆盖以前的子图。但是,如果在每个子图中绘制了多个表面,则会出现这种情况。不过,+1 以发现错误。
    【解决方案2】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 2016-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-16
      • 2014-05-30
      相关资源
      最近更新 更多