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

3 Ansichten (letzte 30 Tage)
SETH GERSBACH am 17 Apr. 2022
Kommentiert: SETH GERSBACH am 18 Apr. 2022
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
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Voss am 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 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
SETH GERSBACH am 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

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by