How an array with 'n' elements, and replicate each element 'm' times and then replace it in the array ?

Hello I need some help, I have a random array of e.g. 10 elements
A= [1 -1 1 1 -1 -1 -1 1 1 -1],
I want to replicate each element in the e.g. 3 times so new array becomes becomes like
B= [1 1 1 -1 -1 -1 1 1 1 1 1 1 -1 -1 -1 .......] and so on,
Can anyone tell me which function would be suitable or any logic that can be applied, as the random array has originally longer lengths and the replication values are higher. I don't want to replicate the whole array 'm' times but each element in array should be replicated as 1 replicated and replaced by 1 1 1 and -1 would be as -1 -1 -1.
Any help would be really appreciated.

 채택된 답변

A= [1 -1 1 1 -1 -1 -1 1 1 -1],
B=repmat(A,3,1);
B=B(:)'
%or
A= [1 -1 1 1 -1 -1 -1 1 1 -1],
B=reshape(repmat(A,3,1),1,[])

추가 답변 (2개)

If you have the Image Processing Toolbox:
B = imresize(A, [1, 3*size(A,2)], 'nearest')

댓글 수: 3

Thanks a lot, I am using it for BPSK modulation, with an array of random size and random elements.
If I have a larger array of more than 1000 elements should I use the length function and defined the length and then repmat it
I don't see why you need to do that if you can use imresize().
Since you now accepted the repmat answer I guess you don't have the IPT. But that's fine, whatever works.

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

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2014년 3월 12일

댓글:

2014년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by