Search code examples
matlabmatlab-figure

Get multiple axes handles at once


I am looking for a one-liner to get multiple axes handles at once in an object array so that it can be passed into linkaxes. I am specifically looking for a single-line statement that does not use loops. I know I have done this in the past with a couple nested functions, but I can't figure out what I did.

The function gca can be used to get the axes handle for a specific figure, though this functionality does not appear to be documented. For example, call gca(3) to get the axis handle for Figure 3. I thought in the past I could call gca([1:4]) to get all four axes handles, but that does not seem to work.

I know that I can use get by calling get([1:4],'currentaxes'), which returns a cell array of axes handles. However, I have not figured out a way to convert a cell array of objects into an object array.

I'm using MATLAB R2015a.


Solution

  • Beside the answers already posted, a possible one-line solution could be:

    linkaxes(findobj('type','axes'))
    

    it also allows implicitly prevent considering figure without axes.

    Hope this helps.