Borrar filtros
Borrar filtros

How to continuously update an existing plot?

108 visualizaciones (últimos 30 días)
Nadia A
Nadia A el 27 de Dic. de 2016
Comentada: Stephen23 el 27 de Dic. de 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

Respuesta aceptada

Stephen23
Stephen23 el 27 de Dic. de 2016
Editada: Stephen23 el 27 de Dic. de 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.
For example, to plot a simple function:
>> 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 comentarios
Nadia A
Nadia A el 27 de Dic. de 2016
Editada: Nadia A el 27 de Dic. de 2016
Thank You Stephen.. Each dataset will have 5 plots and each plot will have plots of 3 versions in it. How do I save all the handles? Can it be assigned to an array of structures?
In my program, first all the datasets for one version will be executed followed by other versions.
Stephen23
Stephen23 el 27 de Dic. de 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:
"Use the gobjects function to preallocate arrays for graphics objects."

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by