フィルターのクリア

Is it possible to use variables stored in the workspace inside another function ?

1 回表示 (過去 30 日間)
HN
HN 2020 年 4 月 22 日
コメント済み: Star Strider 2020 年 4 月 23 日
Is it possible to use variables stored in the workspace inside another function?
  3 件のコメント
Stephen23
Stephen23 2020 年 4 月 22 日
@HN: global variables and evalin are two anti-pattern options that you should definitely avoid using, unless you really want to force yourself into writing slow, compplex, obfuscated, buggy code that is difficult to debug.
The MATLAB documentation clearly states the the best practice is to pass input/output arguments:
Johannes Hougaard
Johannes Hougaard 2020 年 4 月 22 日
agreed @Stephen - it's hideous and obscure...(but possible)

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

採用された回答

Star Strider
Star Strider 2020 年 4 月 22 日
The best option is to pass them to the function as extra parameters. See: Passing Extra Parameters for an extended discussion.
  6 件のコメント
HN
HN 2020 年 4 月 23 日
編集済み: HN 2020 年 4 月 23 日
I found it a bit harder to catch up the pass variable. Can you be a bit more specific please. Example.
When I run the for loop W is saved into the workspace. After finishing the for loop I wanted to use W inside fqdot function. How can I pass W into this funciton to compute omg?
Thank you so much for the help.
Star Strider
Star Strider 2020 年 4 月 23 日
Please see the documentation on Passing Extra Parameters that I linked to in my original post.
I have no idea what you are doing in your code (other than it appears to be a Runge-Kutta integrator).

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScope Variables and Generate Names についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by