필터 지우기
필터 지우기

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

조회 수: 20 (최근 30일)
Mr Anderson
Mr Anderson 2016년 4월 3일
댓글: Jay 2019년 8월 28일
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에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by