Stacking matrices in a larger matrix in a loop

1 回表示 (過去 30 日間)
Danny Coles
Danny Coles 2013 年 11 月 8 日
コメント済み: Danny Coles 2013 年 11 月 8 日
I now need to stack matrices formed in a loop on top of each other to create a larger matrix.
For example, I have a loop that goes around 4 times, each time it creates a 9 x 4 matrix. I need to store each iterative matrix in a larger matrix by stacking them one on top of each other, to get a matrix of dimensions 36 x 4.
Any ideas how I can do this?
Cheers
Danny

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 8 日
out=zeros(36,4) % Pre-allocate
for k=1:4
A=rand(9,4);
out((k-1)*9+1:k*9,:)=A
end
  1 件のコメント
Danny Coles
Danny Coles 2013 年 11 月 8 日
Hi Azzi,
Thanks for this, it makes sense, however I need to perform this operation for a cell of dimension 9 x 4 which includes text and numbers, rather than a matrix.
When I try this I get an error message that says:
The right hand side of this assignment has too few values to satisfy the left hand side.
Any ideas why this may be?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by