필터 지우기
필터 지우기

How to repeat different vectors to form another vector?

조회 수: 1 (최근 30일)
xiaojuezi
xiaojuezi 2020년 8월 7일
댓글: xiaojuezi 2020년 8월 7일
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.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 8월 7일
repmat()
  댓글 수: 2
Fangjun Jiang
Fangjun Jiang 2020년 8월 7일
%%
k=5;
a=1:k*3;
b=reshape(a,3,[]);
c=repmat(b,3,1);
d=c(:)'
xiaojuezi
xiaojuezi 2020년 8월 7일
Thank you very much!

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

추가 답변 (1개)

Sudheer Bhimireddy
Sudheer Bhimireddy 2020년 8월 7일
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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by