How to click the subplots

조회 수: 11 (최근 30일)
Aravin
Aravin 2017년 1월 8일
댓글: Walter Roberson 2019년 5월 6일
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에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by