How to continuously update an existing plot?
179 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nadia A
am 27 Dez. 2016
Kommentiert: Stephen23
am 27 Dez. 2016
Hi
I have a program in which user can choose any or multiple versions of an activity to run one after another. Each version is run over 5 datasets. 5 plots will be generated for each dataset. So I will have a total of 25 plots for each version. If I run all three versions, then a total of 5*5*3 plots will be generated which will become messy. So instead of generating all the plots, I want to merge the corresponding plot of each version for a particular dataset i.e. plot #1 of dataset#1 version#1 should be merged with plot#1 of dataset#1 version#1 and so on. How do I do this without opening and closing the plot?
Thanks
Nadia
0 Kommentare
Akzeptierte Antwort
Stephen23
am 27 Dez. 2016
Bearbeitet: Stephen23
am 27 Dez. 2016
Instead of creating lots of figures, the idea is to create one plot and alter its properties. This could mean altering its data points, or axes, or orientation, or whatever you require.
Create just one figure (or a very small number), and always keep track of the graphics handles of everything that you plot. All graphics functions return a handle (well, most of them), and you can use this handle to specify where to plot your data, to delete, or alter parts of a figure, axes, line, patch, text, or any other graphics object.
Create the figure once, and then do not close it: simply change it as required, and ditto for its contents: add or delete axes, lines, patches, etc.
>> fgh = figure(); % create a figure
>> axh = axes('Parent',fgh); % create axes
>> X = 0:0.1:pi;
>> Y = sin(X);
>> lnh = plot(axh,X,Y); % plot in those axes
Now you can use set and get to alter properties of the objects (or dot notation of using R2014b or more recent). Note that you will need to carefully read the list of object properties (e.g. line properties), and be aware that sometimes multiple properties may need to be changed to get the desired effect:
>> set(lnh,'XData',[0,1,2],'YData',[1,2,1]) % change the line data
You can delete or change any graphics objects:
>> cla(axh) % clear those axes
Now that the axes are clear simply plot some new data... and so on.
To get the best information read the MATLAB documentation:
2 Kommentare
Stephen23
am 27 Dez. 2016
@Nadia A: how you save handles depends on the MATLAB version. Prior to 2014b handles were numeric values, so they could be saved in simple double arrays. Since 2014b they are objects which need to be saved. At this point you can refer to the links that I gave you: open this page and scan down the page:
and you will find the text "...preallocating, and object arrays". Click the link to open this:
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Object Programming 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!