Matlab: replace one plot maintaining others

前端 未结 1 1791
耶瑟儿~
耶瑟儿~ 2021-01-27 16:51

I have a figure in which I plot some disperse points and then a trajectory. I want to switch between different trajectories by plotting them in the same figure as the points, bu

相关标签:
1条回答
  • 2021-01-27 17:51

    Perhaps this little demo will be helpful:

    xy = rand(20,2);
    figure
    % Plot first iteration and output handles to each
    h = plot(xy(:,1),xy(:,2),'b.',xy(1:2,1),xy(1:2,2),'r-');
    axis([0 1 0 1])
    
    % Update second plot by setting the XData and YData properties of the handle
    for i = 2:size(xy,1)-1
        set(h(2),{'XData','YData'},{xy(i:i+1,1),xy(i:i+1,2)})
        drawnow
        pause(0.1);
    end
    

    You should read up on handle graphics in Matlab and the get and set functions.

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