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

9 次查看(过去 30 天)
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 ! :)

采纳的回答

Jan
Jan 2016-4-3
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 个评论
Mr Anderson
Mr Anderson 2016-4-3
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 :)

请先登录,再进行评论。

更多回答(2 个)

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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by