How I multiply matrices in a cell?
Show older comments
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 )
Answers (1)
KSSV
on 1 Jun 2022
% 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 Comment
Sourabh Jain
on 1 Jun 2022
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!