Animated PLOT in GUI

6 vues (au cours des 30 derniers jours)
Adam Horvath
Adam Horvath le 29 Avr 2020
Modifié(e) : Adam Danz le 4 Mai 2020
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 commentaire
Geoff Hayes
Geoff Hayes le 29 Avr 2020
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?

Connectez-vous pour commenter.

Réponses (1)

Adam Danz
Adam Danz le 29 Avr 2020
Modifié(e) : Adam Danz le 4 Mai 2020
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.

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by