I have this function thats supposed to rotate a 2x2 matrix (arm) by theta.
I think i have to multiply the arm matrix by a rotation matrix to be given the new arm but i can't figure out how to do it. I keep getting error messages saying that arm and the rotation matrix is of different sizes.

 채택된 답변

KSSV
KSSV 2021년 2월 12일
편집: KSSV 2021년 2월 12일

1 개 추천

L = rand(2,2) ; % line
% Rotation matrix
R = @(theta) [cos(theta) -sin(theta) ; sin(theta) cos(theta)] ;
% Get mean
m = mean(L) ;
L1 = m+(L-m)*R(pi/2) ; % rotate line by 45 degrees
plot(L(:,1),L(:,2),'r',L1(:,1),L1(:,2),'b')

댓글 수: 6

Paul Jackson
Paul Jackson 2021년 2월 12일
I tried applying it like this
R = [cos(theta) -sin(theta);sin(theta) cos(theta)];
m = mean(arm);
[arm_rot]=m+(arm-m)*R(theta);
I got the error message
Error using *
Incorrect dimensions for matrix multiplication.
KSSV
KSSV 2021년 2월 12일
편집: KSSV 2021년 2월 12일
What is size of arm? It should be compatible to multiply with 2*2 rotation matrix.
Paul Jackson
Paul Jackson 2021년 2월 12일
I cant actually see it but i just checked the dimensions using height and width command and it turned out to be height=2 and width=10
how would you apply the rotation to this?
KSSV
KSSV 2021년 2월 12일
Transpose it before finding mean and transpose after calculations are done.
arm.' * R
would be 10 x 2 * 2 x 2, giving a 10 x 2 result. You could then transpose that to 2 x 10.
(arm.' * R).'
You might also be able to just use
R * arm
Paul Jackson
Paul Jackson 2021년 2월 12일
편집: Paul Jackson 2021년 2월 12일
That worked, thanks guys!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

2021년 2월 12일

편집:

2021년 2월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by