Syntax to multiply 10 different 2 by 2 matrices sequentially in matlab

Please I need help with syntax to multiply ten 2 by 2 matrices i.e T = A1*A2*A3*A4*A5*A6*A7*A8*A9*A10 in matlab

댓글 수: 2

"Matrix" multiplication, or "element-by-element" multiplication?
Sir I need syntax for element by element multiplication called from the output of a for loop manipulation. Say T is the output that contains ten different 2 by 2 matrix from the for loop. How do i get their product in this form: T = T1*T2*T3*...* TN TO obtain a SINGLE 2 by 2 answer Thanks

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

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 9월 14일
편집: Andrei Bobrov 2013년 9월 14일
A = cat(3,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10);
s = size(A,3);
out = A(:,:,1);
for jj = 2:s
out = out*A(:,:,jj);
end
or
A = {A1,A2,A3,A4,A5,A6,A7,A8,A9,A10};
out = A{1};
for jj = 2:numel(A)
out = out*A{jj};
end
or for "element by element" multiplication
A = cat(3,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10);
out = prod(A,3);

댓글 수: 2

Segun  Emmy
Segun Emmy 2013년 9월 14일
편집: Segun Emmy 2013년 9월 14일
Thanks for your quick response please what code do I include if this ten 2 by 2 matrices are outputs from a for loop to reference them or call them from the output "A" instead of listing them as A1,A2,A3 etc

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

추가 답변 (1개)

For element by element multiplication, I believe this should work:
T = A1.*A2.*A3.*A4.*A5.*A6.*A7.*A8.*A9.*A10
If the A's are of class integer, you'll have to watch out if they exceed the max value, intmax('uint8') or intmax('uint16'), or else your product will be clipped. Cast to double before multiplication if that's the case.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by