【问题标题】:two simultaneous plots in matlabmatlab中的两个同时绘制的图
【发布时间】:2013-06-13 12:52:54
【问题描述】:

我想在 Matlab 中的两个不同位置同时绘制两个绘图,循环动画,两者都是不同的动画,一个是暂停,另一个是暂停。

另外,一个是 2D,一个是 3D

我正在做这样的事情:

for i=1:some_number
    axes('position',...)
    plot(...);hold on;
    axes('position',...)
    clf
    plot3(...) (or fill3 but has to do with 3d rendering)
    view(...)
    set(gca, 'cameraview',...)
    set(gca,'projection',...)
    mov(i)=getframe(gcf)
end

第一季度。 set 属性会影响第一个轴吗?如果有,如何避免?

第二季度。在我的情节中,坚持没有用。两者都是瞬间的。喜欢使用延迟。如何让它发挥作用?

第三季度。我希望 mov 记录两个轴。

附:我希望 clf 不是问题。我必须使用 clf 或者如果有更适合我情况的等价物,请建议我。

【问题讨论】:

    标签: matlab animation plot axes


    【解决方案1】:

    您需要存储来自axes 函数的返回值,并在给定 轴上专门通过后续函数调用进行操作,而不仅仅是当前轴。 p>

    % Create axes outside the loop
    ax1 = axes('position',...);
    ax2 = axes('position',...);
    
    hold(ax1, 'on');
    
    for i=1:some_number
        plot(ax1, ...);
    
        cla(ax2); % use cla to clear specific axes inside the loop
        plot3(ax2, ...) (or fill3 but has to do with 3d rendering)
        view(ax2, ...)
        set(ax2, 'cameraview',...)
        set(ax2,'projection',...)
    
        mov(i)=getframe(gcf)
    end
    

    【讨论】:

      【解决方案2】:

      这是我的一段代码中的一个 sn-p,它绘制了三个天体的轨道,我认为这会对你有所帮助:

      for i = 1:j,   %j is an arbitrary number input by the user
      
          plot(x, y, '*')
          plot(x2, y2, 'r')
          plot(xa, ya, '+')
      
          grid on
          drawnow   %drawnow immediately plots the point(s)
          hold on   %hold on keeps the current plot for future plot additions
      
          %dostuff to x,y,x2,y2,xa,ya
      
      end
      

      您想要的两个主要功能是drawnowhold on

      请注意:x、y、x2、y2、xa 和 ya 会随着循环的每次迭代而变化,我只是省略了该代码。

      编辑:我相信drawnow 函数将解决您与hold on 相关的问题。

      我认为这可能会解决您的问题。

      for i=1:some_number
          axes('position',...)
          plot(...);
      
          drawnow      %also note that you must not put the ; at the end
          hold on      %see above comment
      
          axes('position',...)
          clf
          plot3(...) (or fill3 but has to do with 3d rendering)
          view(...)
          set(gca, 'cameraview',...)
          set(gca,'projection',...)
          mov(i)=getframe(gcf)
      end
      

      【讨论】:

      • 我不确定你是否理解我的问题。但我从其他地方得到了答案。谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 2013-11-05
      相关资源
      最近更新 更多