How do I return callback value from GUI to workspace
20 ビュー (過去 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
0 件のコメント
採用された回答
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 Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!