How do I return callback value from GUI to workspace

18 次查看(过去 30 天)
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

采纳的回答

Cameron B
Cameron B 2020-1-12
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by