Create a matrix of matrices

58 views (last 30 days)
Connor LeClaire
Connor LeClaire on 19 Oct 2021
Commented: Paul on 19 Oct 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 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 19 Oct 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.
Connor LeClaire
Connor LeClaire on 19 Oct 2021
It is being used for manipulator transformation matricies. At each joint in an arm, there is a 4x4 transformation matrix associated with it, relating the previous joint's frame to the current joint. In each transformation matrix entire matrix will need to be accessed (to multiple all them together) and also constituent parts (for example the first three rows of the 3rd and 4th columns) for multiplication and to become a part of yet another matrix.

Sign in to comment.

Accepted Answer

Paul
Paul on 19 Oct 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,:)
ans(:,:,1) = 
ans(:,:,2) = 
ans(:,:,3) = 
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 Comments
Connor LeClaire
Connor LeClaire on 19 Oct 2021
Edited: Connor LeClaire on 19 Oct 2021
Great thanks!
Is it possible (using cat) to add matricies on after the 3D matrix has already been made? For instance if I had n of these matricies and wanted to calculate them using a for loop and keep adding them on to the master.
A small aside, how did you get the theta's to display using the Greek symbol?
Paul
Paul on 19 Oct 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
A =
A(:,:,1) = 1 0 0 1 A(:,:,2) = 2 0 0 2 A(:,:,3) = 3 0 0 3
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.

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!