Make matlab use a function from a certain toolbox

조회 수: 15 (최근 30일)
Mariella Dreißig
Mariella Dreißig 2019년 9월 9일
댓글: Stephen23 2019년 9월 10일
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
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?
Mariella Dreißig
Mariella Dreißig 2019년 9월 10일
dist is a variable.
C:\Program Files\MATLAB\R2019a\toolbox\shared\rotations\rotationslib\+matlabshared\+rotations\+internal\@quaternionBase\dist.m % Shadowed quaternion method
the second one should be the right function, but cd-ing into the folder does not solve the problem

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
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
Mariella Dreißig
Mariella Dreißig 2019년 9월 10일
oh man I was wondering about that but I didn't see this because in the current script I don't have a 'dist' variable, it was loaded into the workspace from an external script.
Thanks a lot!
Stephen23
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
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.)
  댓글 수: 1
Mariella Dreißig
Mariella Dreißig 2019년 9월 10일
I feel stupid now, I didn't see that it was loaded into the workspace from an external script.. thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by