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

1 回表示 (過去 30 日間)
adi kul
adi kul 2016 年 6 月 6 日
回答済み: Walter Roberson 2016 年 6 月 6 日
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.

回答 (2 件)

Walter Roberson
Walter Roberson 2016 年 6 月 6 日

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 6 月 6 日
You can pass them as arguments
  1 件のコメント
adi kul
adi kul 2016 年 6 月 6 日
can you elaborate? if possible, with example?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by