How to click the subplots

11 Ansichten (letzte 30 Tage)
Aravin
Aravin am 8 Jan. 2017
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.

Antworten (2)

Jan
Jan am 8 Jan. 2017
Bearbeitet: Jan am 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 am 6 Mai 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 Kommentar
Walter Roberson
Walter Roberson am 6 Mai 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

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by