Save Variables declared in function to workplace.

2 ビュー (過去 30 日間)
Aryan Jain
Aryan Jain 2020 年 9 月 23 日
コメント済み: Aryan Jain 2020 年 9 月 23 日
Hello
I am defining variables in a function, but after the execution those variables are not saved in my workplace.
How can I do it without actually returnig them in output.
And the no. of variables are unkown initially , after the user give some values according to it no. of variables are declared in the function and later on all those variables are used to compute the final value and this final value is the output of the function but I need the variables declared for further computation.
  2 件のコメント
Stephen23
Stephen23 2020 年 9 月 23 日
"I am defining variables in a function, but after the execution those variables are not saved in my workplace."
They are defined in the function workspace:
"How can I do it without actually returnig them in output."
The efficient, simple, and recommended way is to pass them as output arguments:
"And the no. of variables are unkown initially"
Then they should be simply stored in one container array, e.g. a cell array or a structure. Then your task is trivial.
Aryan Jain
Aryan Jain 2020 年 9 月 23 日
Thank You sir.

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 23 日
It seems that you are dynamically naming the variables. This is not a recommended practice and should be avoided as much as possible: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval.
However, if you still want to do such a thing that then either use varargout: https://www.mathworks.com/help/matlab/ref/varargout.html or declare these variables as global: https://www.mathworks.com/help/matlab/ref/global.html
  1 件のコメント
Aryan Jain
Aryan Jain 2020 年 9 月 23 日
Thank You sir.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by