Effacer les filtres
Effacer les filtres

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

20 vues (au cours des 30 derniers jours)
Mr Anderson
Mr Anderson le 3 Avr 2016
Commenté : Jay le 28 Août 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 ! :)

Réponse acceptée

Jan
Jan le 3 Avr 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 commentaire
Mr Anderson
Mr Anderson le 3 Avr 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 :)

Connectez-vous pour commenter.

Plus de réponses (2)

Mr Anderson
Mr Anderson le 3 Avr 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 le 31 Mar 2019
why don't you post true code?
set(scatterA2, 'XData', ..., 'YData', ..., 'ZData', ...,'CData',...,'CData',...);
does not work.
  1 commentaire
Jay
Jay le 28 Août 2019
the "..." allows for a new line.
type it in like this
set(scatterA2, 'XData', ...
, 'YData', ...
, 'ZData', ...
,'CData',...
,'CData',...
);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by