How I multiply matrices in a cell?

I have 5 x 19 cell. Each cell has 2 x 2 matrix. I need a 1 x 19 cell which has matrix product of each matrice from individual column.
For a 1 x 5 cell (M_transfer) having 2 x 2 matrix I am able to get matrix product (M1 x M2 x .... x M5) by following code:
M = 1 ; %dummy variable
for i = 1 : 5
M = M * M_transfer{1,i} ;
end
How I do this for 5 x 19 cell? (In final answer I need 19 matrix products stored in a 1 x 19 cell )

답변 (1개)

KSSV
KSSV 2022년 6월 1일

1 개 추천

% Make dummy data for demo
C = cell(5,19) ;
for i = 1:5
for j = 1:19
C{i,j} = rand(2) ;
end
end
M = @(x) prod(x(:)) ; % function to multiple all elements of each 2x2 matrix in each cell array
A = cellfun(M,C) ;
B = prod(A) % multiply 5 column elements of A

댓글 수: 1

Sourabh Jain
Sourabh Jain 2022년 6월 1일
Thanks for answering but I thing you misunderstood part of my question. Please refer to image for better explanantion.

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2021b

태그

질문:

2022년 6월 1일

댓글:

2022년 6월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by