MATLAB Answers

How do I return callback value from GUI to workspace

1 view (last 30 days)
Stuart Song
Stuart Song on 12 Jan 2020
Commented: Stuart Song on 14 Jan 2020
As part of a bigger app to analyze people's gait, for this part of the code, I'm trying to detect whether one of the two buttons has been pressed so that it can be followed by an if statement. I've been trying to use a callback function to return value from child function to workspace, not just display in the command window, so that it can keep codes flow but it didn't work. It seems very simple but I can't solve it.
close all
prompt = 'Do you want to optimize Minibatch before processing session data?';
newfigure = figure;
newfigure.Position = [500 350 600 300];
handles.button = 0
button_yes = uicontrol(newfigure,'Style','pushbutton',...
'Position',[50 50 200 100],...
button_no = uicontrol(newfigure,'Style','pushbutton',...
'Position',[350 50 200 100],...
headline = uicontrol(newfigure,'Style','text',...
'Position',[0 200 600 30],...
function button_yes_callback(hObject,eventdata,handles)
handles.button = 1
disp('Fist Button was pressed.');
function hObject = button_no_callback(hObject,eventdata,handels)
handles.button = 0
disp('Second Button was pressed.');


Sign in to comment.

Accepted Answer

Cameron B
Cameron B on 12 Jan 2020
Let’s say the variable you want to send to the workspace is called savethis in your GUI, and let’s say you want the variable in the workspace to be called something different - say savevar. The relevant code would be:

More Answers (0)

Sign in to answer this question.