How to repeat different vectors to form another vector?

1 visualización (últimos 30 días)
xiaojuezi
xiaojuezi el 7 de Ag. de 2020
Comentada: xiaojuezi el 7 de Ag. de 2020
Hi I would like to construct a vector as:
1,2,3,1,2,3,1,2,3,4,5,6,4,5,6,4,5,6.....k-2,k-1,k,k-2,k-1,k
i.e. repeat [1,2,3], [4,5,6].... 3 times. How to do this without a for loop?
Thank you very much.

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 7 de Ag. de 2020
repmat()
  2 comentarios
Fangjun Jiang
Fangjun Jiang el 7 de Ag. de 2020
%%
k=5;
a=1:k*3;
b=reshape(a,3,[]);
c=repmat(b,3,1);
d=c(:)'
xiaojuezi
xiaojuezi el 7 de Ag. de 2020
Thank you very much!

Iniciar sesión para comentar.

Más respuestas (1)

Sudheer Bhimireddy
Sudheer Bhimireddy el 7 de Ag. de 2020
For OPs example, it would be:
>> A = [repmat([1,2,3],1,3) repmat([4,5,6],1,3)] %... repmat([k-2,k,k],1,3)];
>> A =
1 2 3 1 2 3 1 2 3 4 5 6 4 5 6 4 5 6

Categorías

Más información sobre Resizing and Reshaping Matrices 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!

Translated by