MATLAB: If a=[1 2 3], b=[10 20 30], how to create c=[10 20 20 30 30 30]

matrix manipulation

The b matrix i'th element is repeated the number of times the given number in 'a' matrix and placed in matix 'c'. Also if a=[0 1 2], b=[10 20 30] how to get c=[20 30 30]??

Best Answer

c = cell2mat(arrayfun(@repmat,b,ones(size(a)),a,'uni',0));
Related Question