Why do I get an "Unrecognized function or variable 'slerp'" error when calling "slerp"

2 views (last 30 days)
I am getting an "Unrecognized function or variable 'slerp'" error when calling "slerp". When I use "which slerp" or "which -all slerp" from the command window, MATLAB returns "'slerp' not found." Additionally, we can find the documentation for "slerp" by searching for it, but we cannot find the function listed under any of the toolbox pages that it is a part of (Robotics Systems, Navigation, Sensor Fusion and Tracking, etc.)
Here is the code that is used to call "slerp":
q0 = eul2quat([0,0,0]);
q1 = eul2quat([pi/2,pi/4,pi/6]);
slerp(q0,q1,.5)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Nov 2022
Edited: MathWorks Support Team on 30 Dec 2022
"Slerp" is a method of the quaternion class, not a function. Since "slerp" is a method, it will not be on the path. Once the quaternion object is loaded into MATLAB's memory (typically by constructing it), MATLAB loads the methods of the quaternion class. At this point, "which -all slerp" would find the method. 
In the code in your question, the N-by-4 arrays produced by "eul2quat" are passed to "slerp" as arguments. However, "slerp" only accepts quaternion objects as arguments. Since the quaternion objects are never constructed, the "slerp" function is never loaded. 
For this case, there are two potential workflows to achieve the desired result:
1) Use the “quaternion” function to create quaternion objects
Using the “quaternion” function instead of the “eul2quat” function will solve the issue. The code snippet below shows an example that provides the same functionality as the code in your question.
q0 = quaternion([0 0 0], 'euler', 'ZYX', 'frame');
q1 = quaternion([pi/2, pi/4, pi/6], 'euler', 'ZYX', 'frame');
slerp(q0,q1,.5)
2) Use "eul2quat" and then create quaternion objects
If you would prefer to use the “eul2quat” function, you can build a quaternion object from the output before calling the "slerp" method. Please see the code snippet below for an example using this workflow.
x0 = eul2quat([0,0,0]);
x1 = eul2quat([pi/2,pi/4,pi/6]);
q0 = quaternion(x0);
q1 = quaternion(x1);
slerp(q0,q1,.5)

More Answers (0)

Categories

Find more on Satellite Mission Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!