How to halt matlab plot3 scale

后端 未结 2 661
梦如初夏
梦如初夏 2021-01-24 10:17

I want to plot pendulum (which changes position) using plot3 function. Unfortunately, when my dot changes position in loop and is being plotted again, the scale of

相关标签:
2条回答
  • 2021-01-24 10:29

    Try setting the XLim, YLim, and ZLim properties before plotting. For example,

    xlim=[-1 1];
    

    or

    haxe = gca;
    haxe.XLim = [-1 1];
    

    Also, you could set XLimMode, YLimMode, and ZLimMode properties to manual. For example,

    haxe.XLimMode = 'manual'
    

    For more information regarding axis properties see MATLAB's documentation for axis properties.

    0 讨论(0)
  • 2021-01-24 10:34

    Here is a short example in 2D, you can easily apply this also to 3D:

    N = 50;
    x = [1:N;N:-1:1];
    x = repmat(x,2,1).';
    p = plot(x(1),1,'ob','MarkerFaceColor','b');
    xlim([0 51])
    for k = 2:numel(x)
        p.XData = x(k);
        drawnow
    end
    

    The key here is to set xlim before the loop, and then only update the relevant data in the plot (using XData in this case).

    0 讨论(0)
提交回复
热议问题