필터 지우기
필터 지우기

replicate values of a vector

조회 수: 1 (최근 30일)
antonet
antonet 2012년 5월 23일
Dear all,
I have, say the vector A=(1:12)'; and I want to replicate each of the 12 numbers 4 times. Any simple code for this?
thanks in advance

채택된 답변

Friedrich
Friedrich 2012년 5월 23일
Hi,
try repmat:
repmat(A,4,1)
Or for the other direction:
repmat(A,1,4)
In the case you want it repeated like this: [1 1 1 1 2 2 2 2 ....] you can use repmat and reshape:
reshape(repmat(A,4,1),[],1)
  댓글 수: 2
antonet
antonet 2012년 5월 23일
thank you friedrich!
Andrei Bobrov
Andrei Bobrov 2012년 5월 23일
kron(A,ones(4,1))

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by