2 sets of x,y variables, one changing loop, one set, how to plot them and update plot to have both

조회 수: 2 (최근 30일)
I have wrighting a program and want to plot two variables on a graph
The problem is that I know how to update the graph, but I don't know how to update the graph with both values where mass_c is unchanged and mass_o is changed
mass_c [0,0]
%mass centre
mass_o[x,y]
%mass_orbit
graph mass_c and mass_o
while
change mass_o position
set(h, 'XData', mass_o(1), 'YData', mass_o(2) P(2) );
drawnow;
end

채택된 답변

Voss
Voss 2022년 4월 18일
Setting the XData and YData of the line that should change is perfectly good way to update what needs updating (and avoid updating what doesn't).
mass_c = [0,0];
%mass centre
mass_o = [5,5];
%mass_orbit
line('XData',mass_c(1),'YData',mass_c(2),'Color','k','Marker','o');
h = line('XData',mass_o(1),'YData',mass_o(2),'Color','r','Marker','x');
% graph mass_c and mass_o
i = 1;
while i < 100
mass_o = [5*cos(pi/4+i*pi/50) 5*sin(pi/4+i*pi/50)]
set(h, 'XData', mass_o(1), 'YData', mass_o(2));% P(2) );
% change mass_o position
drawnow;
i = i+1;
end
Is there a problem you run into when you try to do that?
  댓글 수: 1
SETH GERSBACH
SETH GERSBACH 2022년 4월 18일
Thank you for your assistance, it does infact work, but I found that starting the plot outside the loop and then having the same plot in the graph, just update the plot.
However your solution is better and more permint then my filler code

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by