set uiaxes in matlab function as current figure to plot on

19 visualizaciones (últimos 30 días)
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:
myFunction(app.uiaxes)
Function:
function myFunction(uiAxes)
axes(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?

Respuesta aceptada

J. Alex Lee
J. Alex Lee el 8 de Oct. de 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.
  7 comentarios
Mario Malic
Mario Malic el 8 de Oct. de 2020
Editada: Mario Malic el 8 de Oct. de 2020
plot(ax,___) creates the line in the axes specified by ax instead of in the current axes (gca). The option ax can precede any of the input argument combinations in the previous syntaxes.
plot function without ax argument, plots into gca - that is of following types:
  • An Axes object.
  • A PolarAxes object.
  • A GeographicAxes object.
  • A standalone visualization
Maybe in one of the future versions they may think of including uiaxes to the list.
CurrentAxes property is useful, but then handle of the figure would have to be stored and "plotting" would actually be changing the Data properties (as mentioned above in Cris' answer), which includes rewriting the old function. Well, changing properties is probably faster than plotting. One can notice the same method used in optimisation plot functions.
You can extend the functionality of the old code, by doing the ctrl+f thing and include axes to plot to, in the old function. add a line on start of the code
ax = gca;
J. Alex Lee
J. Alex Lee el 8 de Oct. de 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)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by