How to: Sharing variable from one function to another function in GUI

1 vue (au cours des 30 derniers jours)
adi kul
adi kul le 6 Juin 2016
Hello All, I am working on a GUI where I want to take input from user and use the variable in another function which is in a separate .m file.
I tried defining the variable as global but still the file where I want to call the value returns "undefined" error.
selection = get(hObject, 'Value');
switch selection
case 1
M2.h=msgbox('Please select the value');
case 2
M2.x2=1;
case 3
M2.x2=2;
case 4
M2.x2=3;
prompt = {'Value1','Value2'};
dlg_title = 'Properties';
num_lines = 1;
defaultans = {'',''};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
M2.Value1=str2num(answer{1});
M2.Value2=str2num(answer{2});
end
set(handles.value_type, 'UserData', M2);
Now I want to call the Value1, Value2 in a separate .m file which runs in the script where above code is. Meaning the above code is a part of GUI which calls the functions from the another m file where I want the above input to be used.

Réponses (2)

Walter Roberson
Walter Roberson le 6 Juin 2016

Azzi Abdelmalek
Azzi Abdelmalek le 6 Juin 2016
You can pass them as arguments

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by