Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Need help figuring out how to save values

1 回表示 (過去 30 日間)
Tomas
Tomas 2014 年 10 月 1 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi. I have a task where I am to call a function multiple times, and I'm not allowed to include any arguments. The code should keep track of how many times it's been called, i.e. the first time the function is called, I should be able to retrieve the value 1, the second time, value 2 etc.
Also, I need to save, each time the function is called, a value that can be accessed the next time that "instance" of the function is called.
For example.
for i = 1 : 10
for j = 1 : 10
abc = Test();
end
end
and then, in the Test function:
% getting hold of j, without it being included as an argument
% save j+1
% the next time j = 1, I should be able to retrieve j+1, and then save another value etc
Thanks a lot in advance :).

回答 (1 件)

Iain
Iain 2014 年 10 月 1 日
As it's homework, I'll just say the keyword you want.
persistent
  1 件のコメント
Tomas
Tomas 2014 年 10 月 1 日
Ok, thanks :).

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by