how to keep variable's value in a recursive function?
27 ビュー (過去 30 日間)
古いコメントを表示
I have a recursive function that basically checks if one situation is true or false. I need to know how many times the case is true. Since if I define a variable within the function, its value will be rewritten in every recursive call. I am wondering if there is any way around it, like access to the work space variable or something.
0 件のコメント
回答 (1 件)
Walter Roberson
2017 年 12 月 13 日
Best approach: return the count of this function and the calls "underneath" it as a second variable.
But you could also use a global variable or a shared variable.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!