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

1 view (last 30 days)
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

Accepted Answer

Voss
Voss on 18 Apr 2022
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 Comment
SETH GERSBACH
SETH GERSBACH on 18 Apr 2022
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

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!