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

 Accepted Answer

Wayne King
Wayne King on 7 Jan 2014
Edited: Wayne King on 7 Jan 2014
B = [];
for ii=1:3
A = randi(10,10); % this is the code to create the 10x10
B = [B ; A];
end

3 Comments

How to do it if I want to do it a million times? Is there a collect way to preallocate?
Ask a separate question @Samuel
Very helpful. Many thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 7 Jan 2014

Commented:

on 27 Oct 2018

Community Treasure Hunt

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

Start Hunting!