- It doesn't make sense to update your graph 1000 times per second (which is what you seem to try above). 30 Times per second is usually enough to get the impression that the animation is fluently.
- The example above is a little silly, x is a scalar, and plotting a scalar doesn't really make sense (or do you want the plot to act like a moving point? If so, consider using the function comet (it may do exactly what you want).
- In order to improve performance dramatically, you should do a plot command once and then update the data of the plot. Otherwise, you will never get a nice animation. It could be the case that this point alone solves your drawnow problem. Using this, the above code would be:
Update axes in Matlab GUI
조회 수: 1 (최근 30일)
이전 댓글 표시
Hey guys I´ve got a question. I have a m-File called Test-Gui.m In this m file I have a simple loop
global x
x=0;
for k=1:1000
x=x+1;
pause(0.001)
end
With this small loop I want to draw a plot in my GUI (Test_GUI.m) and update this plot everytime with the new value for x.
function axes1_CreateFcn(hObject, eventdata, handles)
global x
plot(x,x^2,'r');
I have tried drawnow() but it doesn´t work at all. Do someone know any possibility to update my figure in the GUI with the changing variable x.
댓글 수: 0
채택된 답변
Gijs van Oort
2013년 5월 6일
Maybe you could try a timer. Have a look for 'Timer' in Matlab's documentation. There are many examples and it is not hard at all!
Furthermore,
global x
global P % Handle to the plot
x=0;
P=plot(0,0,'r'); % initialize plot. The data does not matter
for k=1:1000
x=x+1;
pause(0.001)
end
function axes1_CreateFcn(hObject, eventdata, handles)
global x
global P
set (P,'xdata',x,'ydata',x.^2) % Note the .^ in order to do element-wise power instead of matrixwise power
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Animation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!