How to click the subplots

11 次查看(过去 30 天)
Aravin
Aravin 2017-1-8
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.

回答(2 个)

Jan
Jan 2017-1-8
编辑:Jan 2017-1-8
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 2019-5-6
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 个评论
Walter Roberson
Walter Roberson 2019-5-6
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by