Passing variable from MATLAB APP Designer Edit Field to a variable inside a .m file.

42 ビュー (過去 30 日間)
Kuang-Ting Hsueh
Kuang-Ting Hsueh 2022 年 11 月 11 日
回答済み: Chris 2022 年 11 月 14 日
Currently I am able to create a GUI in the Matlab App Designer and I want to connect some of the input edit field value to some variable inside a .m file. How do I do that?
GUI:
function x_valueEditFieldValueChanged(app, event)
value = app.x_valueEditField.Value;
end
.m File:
want the variable x to be what the user input to be
  3 件のコメント
Kuang-Ting Hsueh
Kuang-Ting Hsueh 2022 年 11 月 12 日
Yes, the .m file is meant to be called by the GUI.
Stephen23
Stephen23 2022 年 11 月 14 日
Why not just call the function and pass that data as an input argument?
That would be by far the simplest and most efficient approach.

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

採用された回答

Chris
Chris 2022 年 11 月 14 日
m-file:
function myFun(x)
disp(x);
end
GUI:
Properties
x
end
function x_valueEditFieldValueChanged(app, event)
app.x = app.x_valueEditField.Value;
myFun(app.x);
end

その他の回答 (2 件)

Vijay
Vijay 2022 年 11 月 14 日
You can use ‘load’ function to load your desired variable from a matfile into workspace or a structure.
Example:
S = load("matlab.mat"); %S is a structure
app.EditField.Value = S.myVar;
Hope this helps!
  1 件のコメント
Walter Roberson
Walter Roberson 2022 年 11 月 14 日
They want the opposite. They want the edit field to change one of their variables.

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


Walter Roberson
Walter Roberson 2022 年 11 月 14 日
make x a property of the app. Have your callback do
app.x = app.x_valueEditField.Value;

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by