Create a matrix of matrices
81 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Connor LeClaire
el 19 de Oct. de 2021
Comentada: Paul
el 19 de Oct. de 2021
I am attempting to fit a number of same-sized (a,b) matricies into a 'master' matrix. For the master-matrix M, I would like to call up the constituent matrices with something like M(1) for the first matrix of size (a,b) and M(2) for the second matrix of size (a,b) and so on.
I saw something to do with cells, however I was having trouble putting my symbolic matricies into each cell. I would also need access to specific rows, columns or values in each constituent matrix.
Currently this is done by stacking the constituent matrices into a master matrix, but calling the values requires the index be increased/decreased by a multiple of one of it's lengths (depending on how it's constructed).
2 comentarios
Bjorn Gustavsson
el 19 de Oct. de 2021
The best recommendation might depend on how you're going to use this. So if you can explain what you plan to use the individual/sub-matrices for and how the answers might become better.
Respuesta aceptada
Paul
el 19 de Oct. de 2021
Would an ordinary 3D matrix do the trick? You can access the elements via normal indexing. As far as i'm aware, you'd have to write a small function extract the transformations and do the matrix multiplications.
a = sym([0 174.0 0 0 0 0]');
d = sym([116.3 0 0 118.2 0 130]');
% alpha = sym([pi/2 0 pi/2 -pi/2 pi/2 0]'); % this works, but it might be
% clearer to use
alpha = [sym(pi)/2 0 sym(pi)/2 -sym(pi)/2 sym(pi)/2 0]';
syms theta_1 theta_2 theta_3 theta_4 theta_5 theta_6 real;
theta = [theta_1 theta_2 theta_3 theta_4 theta_5 theta_6]';
%% Calculate Transforms
T_0_1 = robot_transform(a(1), alpha(1), d(1), theta(1));
T_1_2 = robot_transform(a(2), alpha(2), d(2), theta(2));
T_2_3 = robot_transform(a(3), alpha(3), d(3), theta(3));
Tmat = cat(3,T_0_1,T_1_2,T_2_3);
% first three row of third and fourth columns accessed by normal indexing
Tmat(1:3,3:4,:)
function T = robot_transform(a, alpha, d, theta)
%Calculates the transformation matrix
%Using SDH parameters, inputs must be in the order of a-alpha-d-theta
T = [ cos(theta) -sin(theta)*cos(alpha) sin(theta)*sin(alpha) a*cos(theta);
sin(theta) cos(theta)*cos(alpha) -cos(theta)*sin(alpha) a*sin(theta);
0 sin(alpha) cos(alpha) d;
0 0 0 1];
end
2 comentarios
Paul
el 19 de Oct. de 2021
Yes, you can do the cat in a loop if you want
A = eye(2);
for ii = 2:3;
A = cat(3,A,ii*eye(2));
end
A
The theta symbols magically show up when running code on the Answers website with what I think is essentially LiveScript. Try running the code in a LiveScript session.
Más respuestas (0)
Ver también
Categorías
Más información sobre Number Theory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!