How I multiply matrices in a cell?

1 visualización (últimos 30 días)
Sourabh Jain
Sourabh Jain el 1 de Jun. de 2022
Comentada: Sourabh Jain el 1 de Jun. de 2022
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 )

Respuestas (1)

KSSV
KSSV el 1 de Jun. de 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 comentario
Sourabh Jain
Sourabh Jain el 1 de Jun. de 2022
Thanks for answering but I thing you misunderstood part of my question. Please refer to image for better explanantion.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by