How to repeat an array?
49 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
arina octave
el 30 de En. de 2015
Editada: Youssef Khmou
el 30 de En. de 2015
Hi, I have an array a = [1 2 3] and I want to repeat it twice so I'll have b = [1 2 3 1 2 3]. I try this code, and of course it won't work as I want.
a = 1:3;
for n = 1:2
b = a;
end
b
I don't know what I should write in the for-loop. Could anyone help me? Thank you.
0 comentarios
Respuesta aceptada
Youssef Khmou
el 30 de En. de 2015
Editada: Youssef Khmou
el 30 de En. de 2015
Many solutions exist for this problem, the first one is the repmat solution:
a=[1 2 3];
b=repmat(a,1,3);
The second solution consists of using for loop as follows :
b=[];
for n=1:3
b=[b a];
end
2 comentarios
Youssef Khmou
el 30 de En. de 2015
Editada: Youssef Khmou
el 30 de En. de 2015
You are welcome Arina.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!