Trying to separate Quaternion coefficients into array.

조회 수: 2 (최근 30일)
Pawan Kumar Mandal
Pawan Kumar Mandal 2021년 4월 7일
답변: James Tursa 2021년 4월 7일
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;

채택된 답변

James Tursa
James Tursa 2021년 4월 7일
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개)

카테고리

Help CenterFile Exchange에서 Coordinate Transformations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by