필터 지우기
필터 지우기

Step matrix where each value is repeated

조회 수: 9 (최근 30일)
Ben Worrall
Ben Worrall 2021년 4월 22일
댓글: Star Strider 2021년 4월 22일
1) I want to create a 1xN matrix where it increases in steps however each step is repeated x amount of times e.g. [0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5].
In my specific case it will start at 0 go up in steps of 250 and finish at 8000 but each value should be repeated 33 times.
2) I have a matrix that goes up in steps e.g [2 4 6 8], I want a new 1XN matrix that does the same steps but repeats X amount of times e.g [2 4 6 8 2 4 6 8 2 4 6 8...]
In my specific case it will start at 0 go up in steps of 800 until 8000 then go back to 0 and repeat 33 times.
Thanks in advance :)

채택된 답변

Star Strider
Star Strider 2021년 4월 22일
Use the repelem function (introduced in R2015a).
  댓글 수: 3
Ben Worrall
Ben Worrall 2021년 4월 22일
actually sorry I have got this to work for scenario 1 but not 2
Star Strider
Star Strider 2021년 4월 22일
As always, my pleasure!
For the vector, the related function repmat is easier:
v2 = [2 4 6 8];
v2r = repmat(v2, 1, 3);
Here it repeats three times.
I’m not certain what to do with this:
‘In my specific case it will start at 0 go up in steps of 800 until 8000 then go back to 0 and repeat 33 times.
however the repmat function could be appropriate here as well.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by