How to update axes in a GUI properly in a while loop

25 visualizaciones (últimos 30 días)
Mr Anderson
Mr Anderson el 3 de Abr. de 2016
Comentada: Jay el 28 de Ag. de 2019
Hello there,
Im currently trying to animate some data in a GUI. Since i interrupt the animation by hand i created an endless while loop updating all 5 axes like this
while true
plotting_index = plotting_index+1;
axes(handles.axes1)
scatter3(scatter data);
axis([xmin xmax ymin ymax zmin zmax])
view(azimuth,elevation);
axes(handles.axes2)
scatter3(scatter data);
axis([xmin xmax ymin ymax zmin zmax])
view(azimuth2,elevation2);
.
.
.
interrupting condition
end;
Since Im updating 5 Axes this way, the plotting gets pretty slow. Matlab recommended initializing the axes ouside the loop, but then I dont know how to assign the Data1(view,axes_lim) for axes1 and Data2 for axes2...etc. Coueld someone help me on that?
Thanks in advance ! :)

Respuesta aceptada

Jan
Jan el 3 de Abr. de 2016
Remove the "axes(handles.axes1)" lines and use:
scatter3(..., 'Parent', handles.axes1);
Or even better: Create the scatter plot once only and adjust the data afterwards:
scatterH1 = [];
while true
...
if isempty(scatterH1)
scatterH1 = scatter3(scatter data);
else
set(scatterH1, 'XData', ..., 'YData', ..., 'ZData', ...);
end
...
end
  1 comentario
Mr Anderson
Mr Anderson el 3 de Abr. de 2016
Thank you so much! Setting the scatter3 once and just updating the data the following runs through the loop is really much faster.
You really helped me a lot! Thanks again :)

Iniciar sesión para comentar.

Más respuestas (2)

Mr Anderson
Mr Anderson el 3 de Abr. de 2016
My final code for anyone who comes across a similar problem. I used Jan Simons approach and manipulated it for my uses, especially for the view and axis settings.
scatterA1 = [];
scatterA2 = [];
...
while true
...
if isempty(scatterA1)
scatterA1 = scatter3(scatter data...'Parent',handles.axes1);
set(handles.axes1,'view',[azimuth elevation]);
axis(handles.axes1,[xmin xmax ymin ymax zmin zmax]);
else
set(scatterA1, 'XData', ..., 'YData', ..., 'ZData', ...,'CData',...);
end
if isempty(scatterA2)
scatterA2 = scatter3(scatter data...'Parent',handles.axes2);
set(handles.axes2,'view',[azimuth2 elevation2]);
axis(handles.axes2,[xmin xmax ymin ymax zmin zmax]);
else
set(scatterA2, 'XData', ..., 'YData', ..., 'ZData', ...,'CData',...,'CData',...);
end
...
end

Van Thai Pham
Van Thai Pham el 31 de Mzo. de 2019
why don't you post true code?
set(scatterA2, 'XData', ..., 'YData', ..., 'ZData', ...,'CData',...,'CData',...);
does not work.
  1 comentario
Jay
Jay el 28 de Ag. de 2019
the "..." allows for a new line.
type it in like this
set(scatterA2, 'XData', ...
, 'YData', ...
, 'ZData', ...
,'CData',...
,'CData',...
);

Iniciar sesión para comentar.

Categorías

Más información sobre Animation 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!

Translated by