i try to create an array as following by using repmat() function:
i have h array
h = [1 2 3 4 5]
and i want to carry out this:
h2 = [1 1 2 2 3 3 4 4 5 5]
by using repmat() func. i want to make each element of this array(h) double like in h2... please help me out ...

 채택된 답변

Matt Fig
Matt Fig 2011년 3월 22일

2 개 추천

N = 2; % The number of times each element will repeat...
h2 = reshape(repmat(h,N,1),1,N*length(h))

댓글 수: 4

Matt Tearle
Matt Tearle 2011년 3월 22일
or h2 = repmat(h,N,1); h2 = h2(:);
Just because I love the x(:) trick.
Matt Tearle
Matt Tearle 2011년 3월 22일
or h2 = zeros(1,2*length(h)); h2(1:2:end) = h; h2(2:2:end) = h;
Walter Roberson
Walter Roberson 2011년 3월 22일
h2 = reshape(repmat(h,N,1),numels(h)*N,1);
osman yurdakul
osman yurdakul 2011년 3월 22일
thanks for your helping. That's been really worked.

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by