0

all. I'm new to Matlab and I'm a bit stuck. The last piece of the puzzle to run my experiment is to get some human input (expert supervised system). As easy as this may sound, I just can't seem to figure this one out.

I need to display four images to the user, plus an additional fifth figure (button, or could even be another image, doesn't matter). The code should wait until the user clicks any one of those images/figures and should continue afterwards (closing the figures, too). Obviously, I'd need to know which figure was clicked.

GUI programming in Matlab doesn't seem to be documented clearly to me. Or perhaps it's just in a realm that I'm not talented with. It's definitely a lot more confusing than Visual Studio, that's for sure.

Thanks in advance for your time; I greatly appreciate it! :)

Gerry
  • 25
  • 1
  • 4
  • [`waitforbuttonpress`](http://www.mathworks.com/help/matlab/ref/waitforbuttonpress.html)? – chaohuang Nov 15 '12 at 20:25
  • 1
    You can use [Function Handle Callbacks](http://www.mathworks.de/de/help/matlab/creating_plots/function-handle-callbacks.html) for this task. See also [this answer](http://stackoverflow.com/a/4547373/1094064) and [this explanation](http://www.mathworks.de/de/help/matlab/ref/figure_props.html#ButtonDownFcn). – Tobias Nov 15 '12 at 20:32

2 Answers2

2

Could you make all five of the images into buttons? The 'CData' property of a button can be used to display an image on a MATLAB button. See the following links for an example and an explanation (that hopefully makes sense!).

http://www.mathworks.com/matlabcentral/fileexchange/2378-buttons/content/buttons.m

http://www.mathworks.com/support/solutions/en/data/1-16V03/

Acoyrogue
  • 21
  • 1
0

Use menu:

figure(1)
plot...
figure(2)
plot...
figure(3)
plot...
figure(4)
plot...

% this will create a menu of labeled buttons where the user can click
m = menu('Choose a figure','Figure 1','Figure 2','Figure 3','Figure 4','None');

% close all 4 figures
close(1:4)  %will close figures 1 to 4

% --------- your program from here on ---------
if m == 5
     display('You chose no Figure');
else
     display(['You chose Figure:' num2str(m)]);
end
%---------

menu will return a number which corresponds to the option that the user clicked on.

R. Schifini
  • 9,085
  • 2
  • 26
  • 32
  • While this isn't exactly what I was looking for, it's super duper simple and still serves the task I need. I can literally drop this in with what I already have and I'm good to go. I appreciate this answer; thanks a lot for your help :) – Gerry Nov 20 '12 at 16:15