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.

Was it helpful?

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:

  1. you could store the information in the Tag or Userdata of the subplot eg. b=subplot(2,2,3,'Tag','pos3') - use get(b,'Tag') (my favourite)
  2. you could just store the handles in order and then search.
  3. you could figure out using Position from the handle.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top