Search code examples
matlabplotmatlab-figurefigure

Accesing the figure inside the figure to add new plot in MATLAB


I have a complicated figure that is composed of 3-4 plots. Those plots are made in outside function; and I use that function in my own script.

The thing is that I want to add one more plot to the existing one. When I try to do that by using "hold on", it adds itself to the wrong place, not into the right plot.

Also, earlier I wanted to change color, thickness and other properties of this second plot - and then I had opened the first function and change those properties there, but for now it doesn't seems to be the proper way to handle this problem. The function can be overwritten when updating MATLAB toolbox. That's why I want to find a solution to handle all of these changes inside my own function.

Here is the example of my problem

If you have any ideas, thanks for sharing! Mary


Solution

  • Your solution is likely relating this call:

     hAllAxes = findobj(gcf,'type','axes');
    

    This will return all handles to all axes in the current figure. One of the handles, e.g. hAllAxes(1) is the bottom plot (it will always be the same, but as you haven't shown code I can't tell which one).

    Then you can always plot selecting the axes:

    plot(hAllAxes(1),myX,myY);