Given two 1 x n cells namely, C1 and C2, how do I create a new cell C3 such that C3 = {C1(1) C2(1) C1(2) C2(2) C1(3) C2(3) ... } using a for loop?

3 visualizaciones (últimos 30 días)
For example suppose you are given cells
C1 = {[a1 b1; c1 d1] [a2 b2; c2 d2] [a3 b3; c3 d3] [a4 b4; c4 d4]}; C2 = {[e1 f1; g1 h1] [e2 f2; g2 h2] [e3 f3; g3 h3] [e4 f4; g4 h4]};
(i.e. both cells C1 and C2 contain four 2x2 matrices)
How would I using a for loop create a new cell C3 such that
C3 = {C1{1,1} C2{1,1} C1{1,2} C2{1,2} C1{1,3} C2{1,3} C1{1,4} C2{1,4}}.
Afterwards, I plan to use the function cell2mat() and prod() in order to multiply all the matrices.

Respuesta aceptada

Walter Roberson
Walter Roberson el 15 de Oct. de 2016
for K = 1 : 1 %it's a loop
C3 = {C1{1,1} C2{1,1} C1{1,2} C2{1,2} C1{1,3} C2{1,3} C1{1,4} C2{1,4}};
end
Alternately, and less efficiently,
C3 = cell(1,8);
for K = 1 : 4
C3(2*K-1) = C1(1,K);
C3(2*K) = C2(1,K);
end
You can cell2mat(C3) but you are going to get out a plain numeric array, 2 x 16 . If you prod() that, you would get out a 1 x 16 result.
  4 comentarios
Josh
Josh el 15 de Oct. de 2016
I would like to perform algebraic matrix multiplication of each 2x2 matrix.
The cat function does not change the cells to matrices therefore I can not use the prod function.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by