Trying to separate Quaternion coefficients into array.
2 views (last 30 days)
Show older comments
Pawan Kumar Mandal
on 7 Apr 2021
Answered: James Tursa
on 7 Apr 2021
function g = actfun(q) % Activity function is LTF
gw = (abs(q.w+1)-abs(q.w-1))/2;
gx = (abs(q.x+1)-abs(q.x-1))/2;
gy = (abs(q.y+1)-abs(q.y-1))/2;
gz = (abs(q.z+1)-abs(q.z-1))/2;
g = quaternion(gw,gx,gy,gz);
end
Here q is a quaternion
Unrecognized method, property, or field 'w' for class 'quaternion'.
Error in plotQVNNs>actfun (line 71)
gw = (abs(q.w+1)-abs(q.w-1))/2;
0 Comments
Accepted Answer
James Tursa
on 7 Apr 2021
Use the double( ) function to convert to numeric array, then use regular indexing. E.g., try this
function g = actfun(q) % Activity function is LTF
Q = double(q);
gw = (abs(Q(1)+1)-abs(Q(1)-1))/2;
gx = (abs(Q(2)+1)-abs(Q(2)-1))/2;
gy = (abs(Q(3)+1)-abs(Q(3)-1))/2;
gz = (abs(Q(4)+1)-abs(Q(4)-1))/2;
g = quaternion(gw,gx,gy,gz);
end
This could also be vectorized
function g = actfun(q) % Activity function is LTF
Q = squeeze(double(q))';
g = quaternion((abs(Q+[1,1,1,1])-abs(Q-[1,1,1,1]))/2);
end
However, if these are unit quaternions then this function just returns the inputs. For a unit quaternion
Q(1) is between -1 and 1, so Q(1)+1 is between 0 and 2, so abs(Q(1)+1) = Q(1)+1
Q(1) is between -1 and 1, so Q(1)-1 is between -2 and 0, so abs(Q(1)-1) = -(Q(1)-1) = -Q(1)+1
So you get
(abs(Q(1)+1)-abs(Q(1)-1))/2 =
(Q(1)+1 - (-Q(1)+1) ) / 2 =
( 2*Q(1)) / 2 =
Q(1)
Same for the other elements. So I presume this function is intended to work on non-unit quaternions?
0 Comments
More Answers (0)
See Also
Categories
Find more on Coordinate Transformations 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!