set uiaxes in matlab function as current figure to plot on

26 views (last 30 days)
Hi folks,
I had a question on how to plot on uiaxes from an m-file. This question got solved:
I wonder if there's a more elgant way to solve this problem by defining the axes at the beginning of the function and then continuously plot on it instead of defining the axes in every single plot command?! Something like:
Call of function:
function myFunction(uiAxes)
% plot 1
% plot 2
% plot x
It works fine the way it is right now, but what if I have an old function with lots of plot commands I want to include to a gui?

Accepted Answer

J. Alex Lee
J. Alex Lee on 8 Oct 2020
I would argue that it makes more sense (more elegant) to require specifying the parent axes to plot. The way that you want may cut down on some letters, but to me is less elegant and more prone to problems and confusion.
I would take the advice of the comment in the other answer: ctrl+F to update your old code.
J. Alex Lee
J. Alex Lee on 8 Oct 2020
Mario's comment reminds me that while you can set the uifigure's CurrentAxes property, that will probably not help with directing plot commands to specific uiaxes - so really not sure what it's there for (I never looked it up)

Sign in to comment.

More Answers (0)


Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!