Make matlab use a function from a certain toolbox
6 次查看(过去 30 天)
显示 更早的评论
I want to use a function ('dist' for quaternions) from an installed toolbox. Matlab obviously uses another function with the same name and throws an error 'Unable to use a value of type 'quaternion' as an index.'
How do I include a certain toolbox and make matlab use this specific function from that toolbox? Or does anybody has any idea why the function 'dist' is not working with two quaternions?
3 个评论
Rik
2019-9-9
This thread might help solve your issue, although it should already sort this out automatically. What does which dist -all return?
采纳的回答
Rik
2019-9-10
编辑:Rik
2019-9-10
You have assigned something to a variable named dist. That will shadow all functions. The solution is not to use dist as a variable name. See this page for a description of the name precedence.
2 个评论
Stephen23
2019-9-10
"...it was loaded into the workspace from an external script."
The curse of scripts.
This is one of the reasons why experienced users prefer (and recommend) using functions.
更多回答(1 个)
Walter Roberson
2019-9-10
If dist is a variable then the problem is not with MATLAB using the "wrong" function.
The best way to solve this problem is to rename your variable so it is not the same as the name of any function you need to call.
The second best way is to drop in a small function that you can pass your arguments into and which calls the function dist. Since it would be in a different workspace, it would not "see" the variable dist to have a problem with (unless you were to for some reason name a function parameter dist, and the cure for that problem is Don't Do That.)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!