How do I get variables from callback functions in MATLAB
5 次查看(过去 30 天)
显示 更早的评论
I programmed a pushbutton that I want to call to @GetValue function.
The GetValue function creates 2 variables (PupilColumn,BehavColumn). I don't know how to take these variables out from the @GetValue function in order to use them later. How should I program it correctly?
[PupilColumn,BehavColumn]=CreatePush(Figure_h,ColumnPupil_h,ColumnBehav_h)
function CreatePush(Figure_h,ColumnPupil_h,ColumnBehav_h)
PushButton_h = uicontrol(Figure_h, 'Style', 'push', 'String', 'Next', ...
'Position', [600 20 120 50], ...
'CallBack',{@GetValue,ColumnPupil_h,ColumnBehav_h}, ...
'UserData',0);
end
function [PupilColumn,BehavColumn] = GetValue(PushButton_h,ed,ColumnPupil_h,ColumnBehav_h)
0 个评论
采纳的回答
Walter Roberson
2011-2-14
Daniel is correct that callbacks cannot return anything. See the FAQ on this topic for various methods.
更多回答(1 个)
Daniel Shub
2011-2-14
I do not think that callback functions can return anything. The variables PupilColumn and BehavColumn can be added to the application data (setappdata) of either PushButton_h or Figure_h.
setappdata(Figure_h, 'PupilColumn', PupilColumn);
Then when you want to use PupilColumn
PupilColumn = getappdata(Figure_h, 'PupilColumn');
This requires you to know Figure_h in order to get PupilColumn.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!