App Designer: plot on Axes out of function

Hi everyone,
I created a GUI in App Designer with an Axes-Object on it. Now I want to enter some values via different buutons/slider etc., calculate some stuff and then plot my results on this Axes-Object.
I made a function as m-file which I call to draw/plot all the stuff I want. This is how I call the function:
drawFunction(Data, app.Axes);
In drawFunction I call
function drawFunction(Data, Axes)
axes(Axes)
... % plot stuff
But all the plots I call are drawn to a new figure which opens and not to my Axes on the GUI. Where is my mistake?

1 comentario

Maybe its the line
axes(Axes).
You can directly specify the axes to plot in most plotting functions as the first argument.
plot(Axes,1:10,1:10);

Iniciar sesión para comentar.

 Respuesta aceptada

Mario Malic
Mario Malic el 7 de Oct. de 2020
Editada: Mario Malic el 7 de Oct. de 2020
In App Designer, those are uiaxes.
In the plot function, you can specify axes to plot to
plot(Axes, 1, 1, 'kd')

6 comentarios

plot(Axes,x,y)
this works fine.
But I have also objects I calculate, like some boxes which should be filled with a special color etc.
Looks something like this:
%calculation
plot(Axes,x,y)
hold on
%calculation
fill(Axes,x,y)
...
The code works fine and the figure it creates is just what I want so see. But if I add the Axes to every single command which draws/plots something, the result looks bad. With every plotted item I add to my Axes, all recently plotted stuff get's hidden. The result is not longer what it should be.
Mario Malic
Mario Malic el 7 de Oct. de 2020
Editada: Mario Malic el 7 de Oct. de 2020
In your hold on, specify Axes.
hold(Axes, 'on')
Dominik Müller
Dominik Müller el 7 de Oct. de 2020
That's it!!!!! Thank you!!!
Dominik Müller
Dominik Müller el 8 de Oct. de 2020
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?!
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?
Mario Malic
Mario Malic el 8 de Oct. de 2020
Editada: Mario Malic el 8 de Oct. de 2020
I doubt so, gca does not accept uiaxes, you can replace your 'plot(' by 'plot(ax,' by using Find option (Ctrl+F).
This is worth of a question (if it's not asked already), so maybe someone else will have an idea how to do it.
Dominik Müller
Dominik Müller el 8 de Oct. de 2020
I started a new question on it.
https://www.mathworks.com/matlabcentral/answers/608241-set-uiaxes-in-matlab-function-as-current-figure-to-plot-on

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 7 de Oct. de 2020

Comentada:

el 8 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by