Share script variable with GUI variable
Mostra commenti meno recenti
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!
Risposte (1)
Stephen23
il 28 Feb 2018
0 voti
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.
Categorie
Scopri di più su Startup and Shutdown in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!