MATLAB Answers

Load variables from worspace to app designer

4 ビュー (過去 30 日間)
Khalala Mamouri
Khalala Mamouri 2020 年 7 月 14 日
コメント済み: Adam Danz 2020 年 7 月 14 日
Hi coders !!!
I am looking for a way to load data from the workspace to app designer, in order to : When i click on a button, data is loaded from worspace to be used in my app
Thanks for the answers !!

  0 件のコメント

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

採用された回答

Adam Danz
Adam Danz 2020 年 7 月 14 日
That's bad design.
  • What if the variable isn't in the base workspace?
  • What if the variable name in the base workspace changes?
  • What if the base workspace variable is overwritten?
  • What if a completely different variable with the same name is present in the base workspace?
  • If someone is reading your code to figure out how it works or to reproduce your results, there's absolutely no way for them to know where the value comes from. Even if you explain it well in a comment, it's still not reproducible.
The big question is, where did the workspace variable come from in the first place?
If the variable was entered directly by the user, use a dialog box to request the value from the user. The value will be entered directly into the app.
If the variable came from a mat file or some other input file, the app should read it / load it directly.
If the variable came from some other function, double yikes! The function should be called from the app directly rather than being called externally and then loaded into the app artificially.
If the variable is a product of many computations performed in the base workspace, again, double yikes! That can all be done within the app or within a single function that the app calls.
The main take-home message is to pass variables into the app by output functions to external or internal functions or by dialog boxes that request direct entry of data from the user.

  2 件のコメント

Khalala Mamouri
Khalala Mamouri 2020 年 7 月 14 日
Yes, i am totaly ok with All what you've said. But i need to take thèse values from the workspace beacause they came from a simulink calculation. There is Other way to do it.
This is the solution a found
Name_the_variable = evalin ('base','Name_of_the_variable_in_workspace');
Works fine for me thank you for the Answer !
Adam Danz
Adam Danz 2020 年 7 月 14 日
That's what we try to convince users not to do.
Here's a summary why not to use eval / evalin etc.
Here are alternatives to eval / evalin etc.
Now that I know the data are coming from simulink, I can point you toward two similar questions that have been answered regarding how to pass data from simulink to app desginer.
I have less experience with Simulink but I can help out if you have any more questions about the appdesginer end.

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

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by