채택된 답변

Fabio Freschi
Fabio Freschi 2020년 3월 4일

0 개 추천

You can do this in a for loop or using arrayfun
% your A vector
A = rand(1,1001); % dummy vector
% calculation of the matrix B
B = arrayfun(@(a)[cos(-a) sin(-a) 0; -sin(-a) cos(-a) 0; 0 0 1],A,'UniformOutput',false);
Than you can access each matrix using the {} indexing, e.g. the first matrix is
B{1}
etc

댓글 수: 5

Missael Hernandez
Missael Hernandez 2020년 3월 4일
편집: Missael Hernandez 2020년 3월 4일
u_body=[y(:,1)];
v_body=[y(:,2)];
w_body=[y(:,3)];
phi=[y(:,7)];
theta=[y(:,8)];
psi=[y(:,9)];
Rz = arrayfun(@(a)[cosd(-a) sind(-a) 0; -sind(-a) cosd(-a) 0; 0 0 1],psi,'UniformOutput',false);
Ry = arrayfun(@(a)[cosd(-a) 0 -sind(-a) ; 0 1 0 ; sind(-a) 0 cosd(-a)],theta,'UniformOutput',false);
Rx = arrayfun(@(a)[1 0 0; 0 cosd(-a) sind(-a) ; 0 -sind(-a) cosd(-a)],phi,'UniformOutput',false);
Ok so phi, theta, and psi are three 1001X1 column vectors. I want to take phi_(1,m), theta_(1,m), and psi_(1,m), and plug them into Rx, Ry, and Rz respectively. Then I want to multiply those results to obtain a 3X3 matrix. How do I do that?
% choose an index
index = 1;
% get the rotation matrix
R = Rx{index}*Ry{index}*Rz{index};
is this what you want?
Missael Hernandez
Missael Hernandez 2020년 3월 4일
편집: Missael Hernandez 2020년 3월 4일
Yes but I want to do it for all 1001 values at the same time
Add
R = cellfun(@(Rx,Ry,Rz)Rx*Ry*Rz,Rx,Ry,Rz,'UniformOutput',false);
Missael Hernandez
Missael Hernandez 2020년 3월 4일
what if I want to multiply each individual R by another vector?

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by