Assign figure to axes gui

2 views (last 30 days)
Georg Söllinger
Georg Söllinger on 2 Dec 2016
Answered: Geoff Hayes on 4 Dec 2016
Hi everybody,
again I need your help with matlab programming: I am trying to implement a code, which is composed of several functions, into a GUI. It works fine but I have my difficulties with assigning the figures, which are created in functions, to the axes in GUI. Can anyone tell me, how to correctly assign the figure from the function to the axes? I tried to return the figure from the function into the axes handle (handles.axes1 = myfunction(bla1, bla2) ), but this one doesn't work.
Help is very appreciated, thanks in advance.
Georg
  1 Comment
Adam
Adam on 2 Dec 2016
You need to give more information as it isn't obvious what you are doing.
Axes are children of a figure. You don't normally assign a figure to a pre-existing axes.
handles.axes1 = myfunction(bla1, bla2)
is not a good idea if that is in a GUIDE GUI which I assume it is given you are using handles. axes1 is the default name of the first axes created in GUIDE (though I usually change its name) and if this is the case you should never be reassigning something to it in the code.

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 4 Dec 2016
Georg - if your function is plotting or drawing some data on to an axes, then if you want to draw it to a specific axes (like the one from your GUI) then you should pass the handle of the axes that you wish to draw to. For example, from within your GUI code, you would call your function as
myfunction(bla1, bla2, handles.axes1);
where handles.axes1 is the handle to the axes that you wish to draw or plot the data to. You would then need to update the body of this function so that when it calls whatever MATLAB function to draw the data, you pass in the handle to the axes.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects 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!