MATLAB Answers

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

263 views (last 30 days)
Joanne Tamayo
Joanne Tamayo on 6 Apr 2016
Answered: sam0037 on 11 Apr 2016
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 Comment

jgg
jgg on 6 Apr 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.

Sign in to comment.

Answers (1)

sam0037
sam0037 on 11 Apr 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:

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!