Borrar filtros
Borrar filtros

How do I repeat a row a certain number of times?

86 visualizaciones (últimos 30 días)
Joanne Tamayo
Joanne Tamayo el 6 de Abr. de 2016
Comentada: Jesse Ivers el 26 de Jul. de 2023
I have a vector of numbers. i.e [ 1 2 3 4] I want to repeat that specific vector a certain number of times, to make a matrix of x rows. It's just the first row repeating itself x times. So it would be [ 1 2 3 4; 1 2 3 4; 1 2 3 4] If x was 3. However I cannot use repmat nor use an iteration
  1 comentario
jgg
jgg el 6 de Abr. de 2016
Editada: jgg el 6 de Abr. de 2016
Why can't you use those functions? Is this homework? The trick is pretty easy:
v = [1:5];
v = v(ones(1,1000),:);
where x = 1000 here.

Iniciar sesión para comentar.

Respuestas (1)

sam0037
sam0037 el 11 de Abr. de 2016
Hi,
This can be also done using the REPELEM command as follows:
v = [1:4];
repelem(v,[3],[1])
Follow the link below to know more about this function:
  2 comentarios
Madhav Malhotra
Madhav Malhotra el 20 de Abr. de 2021
Editada: Madhav Malhotra el 20 de Abr. de 2021
@sam0037Could you please explain how the second and third arguments in your function work?
The documentation doesn't provide an example of what happens when you put one-dimensional vectors as arguments to repelem.
Jesse Ivers
Jesse Ivers el 26 de Jul. de 2023
They don't have to be vectors, simple ints accomplish the same goal. Not sure why they are bracketed in that example.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating 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