CELLFUN syntax when calling the ATAN2 function for 3 x 3 rotation matrix decomposition
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi
I'm trying to use cellfun to apply the following formulas to elements of 3 x 3 rotation matrices, R, stored within a 1 x n cell array, eulR, to derive euler rotations around x, y, z axes (in radians) returned as a 1 x n cell array, eulV:
R = |r11 r12 r13|
|r21 r22 r23|
|r31 r32 r33|
eulx = atan2(r32, r33)
euly = atan2(-r31,sqrt((r32*r32)+(r33*r33))
eulz = atan2(r21, r11)
When applied to a discrete 3 x 3 array I can get the desired output for eulx, euly and eulz using respectively:
eulx = atan2(R(3,2), R(3,3))
euly = atan2(-R(3,1), sqrt(R(3,2)*R(3,2) + R(3,3)*R(3,3)));
eulz = atan2(ans(2,1), ans(1,1));
e.g. for eulR{1}:
0.9437 -0.0012 0.0084
-0.0058 0.5976 -0.0151
0.0037 -0.0166 0.5831
eulx = -0.0284
euly = -0.0063
eulz = -0.0062
However, I am having considerable difficulties in applying the above formulas to each cell of eulR using cellfun. For example, I have tried to use the following code to solve eulx:
eulV = cellfun(@atan2, eulR(3,2), eulR(3,3), 'Uni', 0);
However, this results in the error: 'Index exceeds matrix dimensions'.
Similarily for euly I have tried:
euly = cellfun(@atan2, -eulR(3,1), sqrt(eulR(3,2)*eulR(3,2) + eulR(3,3)*eulR(3,3)), 'Uni', 0);
However, this gives the error message 'Undefined function 'uminus' for input arguments of type 'cell'.
And for eulz I have attempted to use:
eulz = cellfun(@atan2, eulR(2,1), eulR(1,1), 'Uni', 0);
Whilst this does not return an error, in gives an incorrect output in the for of a 3 x 3 matrix stored in a 1 x 1 cell array.
Apologies if this may seem a fairly trivial syntax error, but I have looked at the documentation and cannot see what these errors are relating to (I am still a bit new to coding in Matlab).
Any help would be greatly appreciated.
Thomas
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 25 de Dic. de 2012
Editada: Azzi Abdelmalek
el 25 de Dic. de 2012
euly=cellfun(@(x) atan2(-x(3,1),sqrt(x(3,2)*x(3,2)+x(3,3)*x(3,3))),eulR);
1 comentario
Ver también
Categorías
Más información sobre C Shared Library Integration en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!