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

3d plotsanimationaxesaxisfigureguiimage analysislooploopsplotplottingwhile loop

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 ! 🙂

Best Answer

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