How to: Sharing variable from one function to another function in GUI
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (2 件)
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!