I am trying to replace the function ginput
with the function ginputc
found on fileexchange:
Custom GINPUT from Jiro. I find ginput
very slow to start when first called. ginputc
is faster.
There is one functionality that I was using with ginput
that I am not managing to replicate with ginputc
. I was getting the subplot number when mouse clicking on it.
This is explained here for ginput
:
get-subplot-number-from-ginput
But to make it easier, here is some simple code to replicate the functionality:
figure, hAx_mine(1)=subplot(1, 3, 1); hAx_mine(2)=subplot(1, 3, 2);hAx_mine(3)=subplot(1, 3, 3);
[x, y, button] = ginput(1);
[Lia,Locb]=ismember(gca,hAx_mine);
disp(['Locb gives the subplot number that you have clicked: ' num2str(Locb)])
If you try the same in ginputc
it always give the last subplot no matter which one you clicked:
figure, hAx_mine(1)=subplot(1, 3, 1); hAx_mine(2)=subplot(1, 3, 2);hAx_mine(3)=subplot(1, 3, 3);
[x, y, button] = ginputc(1);
[Lia,Locb]=ismember(gca,hAx_mine);
disp(['Locb gives the subplot number that you have clicked: ' num2str(Locb)])
There is an option to get the axe as an extra output from ginputc
:
...
[x, y, button,ax] = ginputc(1);
[Lia,Locb]=ismember(ax,hAx_mine);
...
But that is also not working. I suppose that ginputc
does change the gca
somehow but after many hours trying, I have not managed to find why, and how to fix it.