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

1 次查看(过去 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 中查找有关 Graphics Performance 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by