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?
1 回表示 (過去 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.
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!