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!