Populate Array with duplicate variables
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I am trying to duplicate the elements within a Matlab array according to the position of elements of the array.
For instance,
x = [1,2,3,4,5,6,4,2,7,5,3] should become x1 = [1,1,2,2,3,3,4,4,5,5,6,6,4,4,2,2,7,7,5,5,3,3]
Thanks
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2013년 9월 18일
편집: Azzi Abdelmalek
2013년 9월 18일
x = [1,2,3,4,5,6,4,2,7,5,3]
y=[x;x]
y=y(:)'
%Or
n=2
x=repmat(x,n,1);
y=y(:)'
추가 답변 (1개)
Jos (10584)
2013년 9월 19일
Another ML-trick:
% data
x = [1 4 3 6] ;
n = 2 ;
% engine
y = kron(x,ones(1,n))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!