How do I return callback value from GUI to workspace
19 views (last 30 days)
Show older comments
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
clear
clc
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',...
'String','Yes',...
'FontSize',12,...
'Position',[50 50 200 100],...
'Callback',@button_yes_callback);
button_no = uicontrol(newfigure,'Style','pushbutton',...
'String','No',...
'FontSize',12,...
'Position',[350 50 200 100],...
'Callback',@button_no_callback);
headline = uicontrol(newfigure,'Style','text',...
'String',prompt,...
'Position',[0 200 600 30],...
'FontSize',12,...
'HorizontalAlignment','Center',...
'HandleVisibility','off');
guidata(newfigure,handles)
%%
function button_yes_callback(hObject,eventdata,handles)
handles.button = 1
disp('Fist Button was pressed.');
guidata(hObject,handles);
end
function hObject = button_no_callback(hObject,eventdata,handels)
handles.button = 0
disp('Second Button was pressed.');
guidata(hObject,handles);
end
0 Comments
Accepted Answer
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:
assignin(‘base’,’savevar’,savethis)
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!