0

Consider the following example

f = figure(1);
ax(1)  = subplot(2,1,1);
plot(1:100,randi(50,1,100));
ax(2)  = subplot(2,1,2);
plot(1:100,randi(50,1,100))
[x,  ~] = ginput(2);  
clickedAx = gca

Is there anyway I can the subplot number on which i clicked for ginput from the axes handle properties ? or some other way ?

Suever
  • 64,497
  • 14
  • 82
  • 101
Novice_Developer
  • 1,432
  • 2
  • 19
  • 33

1 Answers1

4

You can use gca to give you the axes that was clicked and compare this to your array of axes using ismember.

[~, axnum] = ismember(gca, ax);

If you don't like specifying two output arguments you could also write

axnum = find(ismember(ax, gca));
Suever
  • 64,497
  • 14
  • 82
  • 101