Animated PLOT in GUI

11 次查看(过去 30 天)
Adam Horvath
Adam Horvath 2020-4-29
编辑: Adam Danz 2020-5-4
Hello Everyone.
I am working on a gui with 4 different animated plots. I got 4 functions for 4 plots and do the animation like:
animatedline command..
for i=1:..
axes(handles.axes1)
values1(i)=subs(function1)...
drawnow
axes(handles.axes2)
values2(i)=subs(function2)...
drawnnow
axes(handles.axes3)
values3(i)=subs(function3)...
drawnow
axes(handles.axes4)
values4(i)=subs(function4)....
drawnow
end
But Matlab has a warning that the axes(...) should be outside of the "for" iteration. How could I fix it?
  1 个评论
Geoff Hayes
Geoff Hayes 2020-4-29
Adam - what is the full warning message? Please copy and paste all of the text to this question. And does it apply to all calls to axes or just one?

请先登录,再进行评论。

回答(1 个)

Adam Danz
Adam Danz 2020-4-29
编辑:Adam Danz 2020-5-4
Here's an example the warning message that appears when calling axes() within a loop.
You're using the axes() command to make a selected axes current so your plotting function plots on the selected axes. There are better ways to do that.
Best method
Don't worry about which axis is current and use axis handles in all of your plotting functions so they are applied to the correct axes. Example:
hold(handles.axes1,'on')
plot(handles.axes1, x, y, '-o')
Alternative method
Set the current figure and then set the current axes within the current figure. Do this just before you do the plotting.
% fig is the handle to your figure
% ax is the handle to an axes within fig
set(0, 'CurrentFigure', fig)
set(fig, 'CurrentAxes', ax)
If the plotting code is lengthy and a user clicks on a different figure or axes after setting the the current axes and before the plotting is complete, the new graphics objects will be assigned to the wrong axes. This is why the first method is much better and fail-proof. The same problem occurs with the axes() solution from your question.

类别

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