MATLAB: Get colorbar handle for a particular image

colorbarhandle graphicsimage

If I have several images as subplots in a figure, how, given a handle to one of the images, or its axis, do I get the handle to the corresponding colorbar? Colorbars are not axes children, so how do I programmatically determine which belongs to which?

Best Answer

Assuming HG2:
get( ancestor(handle, 'axes'), 'Colorbar')
Or, if you already have the axes in variable ax then
ax.Colorbar