save or write variables in function file
古いコメントを表示
Hi,
How do I actually save variables that are in a function file?
1 件のコメント
Jan
2011 年 12 月 28 日
Please explain, what you want to achieve.
回答 (3 件)
Walter Roberson
2011 年 12 月 28 日
1 投票
You cannot do this without altering the function file (or at least one function or script that it calls directly.)
You can, as Titus indicates, use assignin() in the function file. Better, though, would be to return the variables from the function and do the assignment outside of the function.
3 件のコメント
Matt Tearle
2011 年 12 月 28 日
Seconded. Using assignin completely destroys any readability or tracibility of your code. Magicking variables into existence is not recommended. Returning the values as outputs from the function is much clearer and safer.
Titus Edelhofer
2011 年 12 月 28 日
Of course. The original question did not make me think about what the OP really might have wanted to do ...
Titus Edelhofer
2011 年 12 月 28 日
0 投票
Use the function save? ;-)
Titus
2 件のコメント
Aishah
2011 年 12 月 28 日
Titus Edelhofer
2011 年 12 月 28 日
Yes. You can either load them in the base workspace later or use assignin, if you want to bring variables from your function to the base workspace directly.
Sulaymon Eshkabilov
2020 年 9 月 5 日
You can save in two different ways:
- Assign the output variables, e.g.: function [Out1, Out2, Out3, Outn] = MYfunction(In1, In2, In3, InN)
function [Out1, Out2, Out3, Outn] = MYfunction(In1, In2, In3, InN)
% that saves the outputs Out1, Out2, Out3, Out4 when you recall and execute the function file called: MYfunction.
Out1 = In1+In2;
Out2 = In3/In1;
Out3 = In1/In2;
OutN = InN/(In1+In2+In3);
end
2. Use and set up: assignin() % Not recommended for a few good reasons
e.g.: assignin('base','Output1', Out1)
カテゴリ
ヘルプ センター および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!