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 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2016-10-15
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 个评论
Josh
Josh 2016-10-15
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by