Matlab – How to tell legends from axes in Matlab

axesfigurehandlelegendMATLAB

The following stackoverflow qestion:

Matlab: How to obtain all the axes handles in a figure handle?

identifies how to get handles to all of the axes from a figure in Matlab. However, this list will also contain handles to legends, at least in R2008a, which appear to also be axes. How can I tell (programatically) the legends from the real plot axes in a vector of axes handles?

Best Answer

From linkaxes, the code you want is:

ax = findobj(gcf,'type','axes','-not','Tag','legend','-not','Tag','Colorbar');

This will return the handles of all the data axes in the current figure.

Related Topic