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

조회 수: 53 (최근 30일)
Joanne Tamayo
Joanne Tamayo 2016년 4월 6일
댓글: Jesse Ivers 2023년 7월 26일
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
jgg
jgg 2016년 4월 6일
편집: jgg 2016년 4월 6일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

sam0037
sam0037 2016년 4월 11일
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
Madhav Malhotra
Madhav Malhotra 2021년 4월 20일
편집: Madhav Malhotra 2021년 4월 20일
@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 2023년 7월 26일
They don't have to be vectors, simple ints accomplish the same goal. Not sure why they are bracketed in that example.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by