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!