How to write a singler for a code that needs to use Fsolver in a loop ?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi All
is there a way to avoid writing one separate mfile for fsolver function to call it in a loop from the main mfile ?
댓글 수: 0
채택된 답변
Walter Roberson
2020년 3월 20일
You can pass fsolve a function handle. That can be an anonymous function or it can be the handle to a real function. If it is the handle to a real function it must be @ followed by the name of a function that is visible to the calling code, including possibly the name of a function in the same file, or the name of the first function in another file, or a function that is a static method of a loaded class, or (I think) a function that is inside a package reference.
Since R2016b, it has been permitted to store a function at the end of a script. The script can make an @ reference to the function. Versions before that did not have that option and so for those older versions, you effectively needed a different mfile if you wanted a real function instead of an anonymous function.
There is also an old syntax that permits passing the name of a function as a character vector. In very early releases, the current file was searched for those functions too, but for more than a decade, this syntax has only been able to find functions that are the first function in their mfile (and, really obscurely, some package references in some cases.)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Function Handles에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!