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

 Respuesta aceptada

Wayne King
Wayne King el 7 de En. de 2014
Editada: Wayne King el 7 de En. de 2014
B = [];
for ii=1:3
A = randi(10,10); % this is the code to create the 10x10
B = [B ; A];
end

3 comentarios

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de En. de 2014

Comentada:

el 27 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by