How can I plot data as program runs?

36 visualizzazioni (ultimi 30 giorni)
Jonathan Pulman
Jonathan Pulman il 29 Mag 2013
I would like to write a program to simulate planets in orbit for many iterations, for example to see if asteroids will form into a stable orbit after many thousands of iterations.
So far all I can find in Matlab is how to plot an equation etc. Matlab only makes the plot after it has finished doing the calculations.
Is it possible to show data as the program runs, showing for example orbits repeatedly over a long time while it continues running?
Do you have any examples of programs that work like that? I am not very familiar with object oriented programming so an example to play with would be very helpful.
Jonathan Pulman

Risposte (2)

per isakson
per isakson il 29 Mag 2013
Modificato: per isakson il 30 Mag 2013
You need to do something like
set( line_handle, 'Xdata', new_x_ value, 'Ydata', new_y_value )
and see example at the bottom of page Animation
  2 Commenti
Jonathan Pulman
Jonathan Pulman il 30 Mag 2013
Thank you, I will try that. I don't really undedrstand handles yet so this will help me
Eugene
Eugene il 30 Mag 2013
I would use the method by setting the data in the handle. The previous line would be something like:
figure(1);
line_handle = plot(x,y);
while ~finished
[x,y] = calculate();
set( line_handle, 'Xdata', x, 'Ydata', y);
end
As an example:
>> figure(1); clf
>> h = plot([1:10],sin([1:10]*2*pi*0.05));
>> for w=0.01:0.01:0.1; set(h,'Ydata',sin([1:10]*2*pi*w)); pause(1); end

Accedi per commentare.


Image Analyst
Image Analyst il 30 Mag 2013
Of course have the plotting call inside your loop, but if it's a really intensive loop you're probably going to have to put in a "drawnow" right after the call to plot() (or whatever function you're using) to get it to refresh/update the screen immediately. And you may or may not want to plot just the last N points, say the last 500 points, so the call to plot doesn't get slower and slower while just painting over the same pixels on the screen.
  3 Commenti
Image Analyst
Image Analyst il 30 Mag 2013
It depends on what you want to do. Do you want to ADD one additional point to the existing points? Or do you want to clear all the points and plot just the last 500 or so? How many points describing your orbit do you think you'll eventually have if you let this thing run on and on? Millions?
Jonathan Pulman
Jonathan Pulman il 23 Giu 2013
Sorry for delay; I did not know I got another reply.. Well, millions of calculations if it runs for a long time, but it would be only be useful to show the last, say 500. One orbit might be 500 sets of calculations.
Adding one point to existing ones would look nice (like real time) but I presume storing the last 500 then showing them would be quicker.

Accedi per commentare.

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by