Create a matrix of matrices

조회 수: 77 (최근 30일)
Connor LeClaire
Connor LeClaire 2021년 10월 19일
댓글: Paul 2021년 10월 19일
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
Bjorn Gustavsson
Bjorn Gustavsson 2021년 10월 19일
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 2021년 10월 19일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Paul
Paul 2021년 10월 19일
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
Connor LeClaire
Connor LeClaire 2021년 10월 19일
편집: Connor LeClaire 2021년 10월 19일
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 2021년 10월 19일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by