How to write a singler for a code that needs to use Fsolver in a loop ?
1 回表示 (過去 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 Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!