Given a handle to a subplot, can I find the associated subplot index in MATLAB?
Question
I have multiple subplots in a figure. I also have the handle to one of the subplots, which I got through use of the ginputax
function described here.
I now want to get the (integer) subplot index from the handle, so I can plot to the subplot using the subplot command.
[~, ~, ~, subplot_handle] = ginputax(1);
subplot_idx = ?function?( subplot_handle) %# this is the bit I don't know how to do
subplot(u, v, subplot_idx);
plot(x, y);
Is there an easy way to get this index? I realise I could alternatively plot directly to the subplot handle, but I would prefer to get the index out.
Solution
If you already have a handle to the subplot, you can use subplot(subplot_handle)
to plot in an existing subplot.
OTHER TIPS
From what I know not directly as subplots are just axes.
But indirect are many ways:
- you could store the information in the
Tag
orUserdata
of the subplot eg.b=subplot(2,2,3,'Tag','pos3')
- useget(b,'Tag')
(my favourite) - you could just store the handles in order and then search.
- you could figure out using
Position
from the handle.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow