How I multiply matrices in a cell?
1 view (last 30 days)
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 )
0 Comments
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
See Also
Categories
Find more on Logical 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!