Trying to separate Quaternion coefficients into array.

1 visualización (últimos 30 días)
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;

Respuesta aceptada

James Tursa
James Tursa el 7 de Abr. de 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?

Más respuestas (0)

Categorías

Más información sobre Coordinate Transformations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by