How to click the subplots

11 views (last 30 days)
Aravin
Aravin on 8 Jan 2017
Commented: Walter Roberson on 6 May 2019
I want to get the indexces of the subplot if clicked by mouse. For example, I have 10 figures shown by subplot.
for i=1:10
subplot(1,5,i), imshow(img{i});
end
Now if user click image 5, and 8 then somehow I should get variable name C with values 5 and 8.

Answers (2)

Jan
Jan on 8 Jan 2017
Edited: Jan on 8 Jan 2017
function FigH = main
FigH = figure('UserData', []);
for i = 1:10
subplot(1, 10, i); % You need 10 SUBPLOTs for 10 images
image(rand(100,100,3), 'ButtonDownFcn', {@Callback, i}); % Not IMSHOW
end
function Callback(ObjectH, EventData, Index)
FigH = ancestor(ObjectH, 'figure');
disp(Index)
UserData = [get(FigH, 'UserData'), Index];
set(FigH, 'Userdata', UserData);
Now you can call this from e.g. the command line:
FigH = main;
Then click on the images as wanted. Finally you can request:
C = get(FigH, 'UserData')

Ling Mei
Ling Mei on 6 May 2019
the simplest way is just add 'axcopy' to the end of the figure,
such as:
figure();
for i=1:4
subplot(2,2,i);
plot(1:10,rand(1,10)*100,'k','linew',2);
end
axcopy;
You would have a pop-out subplot if you click the area of subplotted figure.
  1 Comment
Walter Roberson
Walter Roberson on 6 May 2019
axcopy appears to be a ucsd function such as http://www.indiana.edu/~pcl/busey/temp/eeglabtutorial4.301/allfunctions/axcopy.m and appears to be included in eeglab
I also find a modified version in erplab

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!