how can I define a global variable in app designer?

102 ビュー (過去 30 日間)
Matteo Paolucci
Matteo Paolucci 2020 年 8 月 16 日
編集済み: Stephen23 2024 年 9 月 2 日
I have to built an app that read data in .csv file and then display and process them.
[file,path] = uigetfile;
tab=readtable(fullfile(path,file));
I used this code for import and save the data but I don't know how can I set them as 'Global variables'.
Can someone help me ?
  4 件のコメント
Kevin Andres Contreras
Kevin Andres Contreras 2020 年 9 月 30 日
¿Me puedes ayudar?
No me quiere copilar
Matteo Paolucci
Matteo Paolucci 2020 年 10 月 3 日
編集済み: Matteo Paolucci 2020 年 10 月 3 日
when you have a variable in app designer, it is not saved as when you'd work on command window. If you want use a variable like 'global variable' in app designer you can do this using 'Properties'.
to be clear:
in this following code the variable y can not be 'seen' in other parts of your code. So you have to write app.variablename and write variablename under the part 'Properties' (it is generated automatically).
x = 1:0.1:100;
app.y=cos(x)
in this way you can use your variable every time you want.
so you have to:
1) use app.variablename for variable you want use in other parts of your code. you have to use app.variablename evry time you call it
2) write variablename under the part of code called 'Propeties'
if you have any difficulties you can write me an email
paolucci.1806891@studenti.uniroma1.it

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

採用された回答

Adam Danz
Adam Danz 2020 年 8 月 16 日
編集済み: Adam Danz 2020 年 10 月 4 日
There are very few reasons, if any, to use global variables in apps and it's usually the sign of trouble.
If the variable is meant to be shared with other functions within the app, declare it as a private variable. If the variable is also needed by external functions or scripts, declare it as a public variable. The link below shows how to do both.
  4 件のコメント
Chikezie Onyema
Chikezie Onyema 2024 年 9 月 2 日
How about loading a very large mat file each time I run app in app designer? How can you not spend minutes loading a file if you have to run the program each time during coding and testing?
Stephen23
Stephen23 2024 年 9 月 2 日
編集済み: Stephen23 2024 年 9 月 2 日
"How can you not spend minutes loading a file if you have to run the program each time during coding and testing?"
Some approaches:

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

その他の回答 (0 件)

カテゴリ

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