MATLAB: I have a function which plot a certain graph. How should I code this so that the function will not deliberately plot in a figure but in the axes of the gui instead

figure

Please see attached image.

Best Answer

You need to tell that plotting command which axes to use, by providing the axes handle. How to do this depends on the plotting command that you are using (you did not state this in your question), but as an example plot accepts the axes handles as the first input argument (here fgh is the figure/tab/panel handle):
axh = axes(fgh,...)
plot(axh,...)
For some other functions you will need to set the 'parent' property, read their help pages and property pages to know the required syntax:
somefun(...,'Parent',axh)
If you want to write reliable code than always obtain and use explicit graphics handles for all graphics functions and operations. Never assume that the current figure/axes/line/patch/... are the ones that you code needs to access. Read more here: