MATLAB: How an array with ‘n’ elements, and replicate each element ‘m’ times and then replace it in the array

array replicateImage Processing Toolbox

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.

Best Answer

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,[])