필터 지우기
필터 지우기

Reusing results of previous function calls

조회 수: 2 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by