2 sets of x,y variables, one changing loop, one set, how to plot them and update plot to have both
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SETH GERSBACH
el 17 de Abr. de 2022
Comentada: SETH GERSBACH
el 18 de Abr. de 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 comentarios
Respuesta aceptada
Voss
el 18 de Abr. de 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?
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!