MATLAB: Save the output of a pushed button

pushbutton save results

Hello everyone
I created several buttons within a figure using the uicontrol function. The subject, moving the mouse, has to press one button out of 6. Now, I would like to save which button the subject has chosen, but I have no idea how to do it.
Any help will be appreciated.
Thank you in advance!

Best Answer

fCallback = @(src,evt) disp( src.String );
figure; hButton1 = uicontrol( 'Units', 'normalized', 'Position', [0.1 0.1 0.35 0.1], 'Style', 'pushbutton', 'Tag', 'button1', 'String', 'Button 1', 'callback', fCallback );
hButton2 = uicontrol( 'Units', 'normalized', 'Position', [0.55 0.1 0.35 0.1], 'Style', 'pushbutton', 'Tag', 'button2', 'String', 'Button 2', 'callback', fCallback );
should give an example of what you want. It isn't necessary to set a Tag, but you can use either the tag or the string to determine which button was pressed if you do set a tag. My example ignores the tag and outputs the string, but strings are not guaranteed to be unique, although in your case I guess they will be.
Obviously you then need to save the information, but you haven't given any details as to what kind of code you are putting these into.
Related Question