Reusing results of previous function calls

3 ビュー (過去 30 日間)
Anton Treialt
Anton Treialt 2018 年 9 月 10 日
回答済み: Jonathan A 2019 年 10 月 9 日
I have a function that is called repeatedly and many function calls have exactly the same inputs. I would like to store the inputs and corresponding results of each call to reuse them, so that if the function is called again with previously used inputs, it would just return the previously computed value, rather than computing it again. In Python you have decorator (@functools.lru_cache) to do this.
What is the best way to implement this functionality in MATLAB?
  1 件のコメント
madhan ravi
madhan ravi 2018 年 9 月 10 日
Can you upload your code? And function file/s

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

採用された回答

Stephen23
Stephen23 2018 年 9 月 10 日
編集済み: Stephen23 2018 年 9 月 10 日

その他の回答 (1 件)

Jonathan A
Jonathan A 2019 年 10 月 9 日
I also looked in this direction but was looking also with the additional feature of persistency across Matlab sessions and a kind of compilation step that builds a dependency graph between functions, such that it is possilbe to executes only parts of the functions to get intermediate results rapidly. This is pretty useful to me when I have complex workflows to manage. Basically, I implemented a class that encapsulates cachedcall and that allows to build a DAG functions. Hope this helps.

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by