How to append vector in a for loop

Hi there,
I have a for loop that creates an 10x10 vector in each iteration. My question is how can I append each 10x10 vector underneath each other after each iteration. So that the final vector is 30x10.
Thank you for your time
for i=1:3
% Do stuff
%result is 10x10 vector A
end

 採用された回答

Wayne King
Wayne King 2014 年 1 月 7 日
編集済み: Wayne King 2014 年 1 月 7 日

9 投票

B = [];
for ii=1:3
A = randi(10,10); % this is the code to create the 10x10
B = [B ; A];
end

3 件のコメント

Sámuel Varga
Sámuel Varga 2018 年 10 月 13 日
How to do it if I want to do it a million times? Is there a collect way to preallocate?
madhan ravi
madhan ravi 2018 年 10 月 13 日
Ask a separate question @Samuel
Raymond MacNeil
Raymond MacNeil 2018 年 10 月 27 日
Very helpful. Many thanks!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2014 年 1 月 7 日

コメント済み:

2018 年 10 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by