Share script variable with GUI variable
显示 更早的评论
Hi MATLAB Community, I'm creating a program that would send a variable from a script workspace to a Matlab GUI workspace. Ideally, I have a script which establishes a variable 'b' which I can access in the command window but not in the Matlab GUI. I understand that the script workspace is different from the GUI workspace.
Is it possible to share 'b' as a 'global variable' so I can rerieve data 'b' in the matlab GUI.
MATLAB SCRIPT
b = 10
GUI SCRIPT PUSH BUTTON
% --- Executes on button press in pairButton.
function pairButton_Callback(hObject, eventdata, handles)
% hObject handle to pairButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
passed_variable = b;
Thank you very much in advance!
回答(1 个)
Stephen23
2018-2-28
0 个投票
First you should pass that variable as an input argument to the GUI function. Then you can use any of the methods described on this page:
The wiki also explains this:
http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
And some of the many threads on this forum that answer your question:
Personally I would recommend that you avoid using GUIDE, and write your own GUI programmatically. Then could use nested functions, which are simple, intuitive, and easy to debug.
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!