MATLAB: How to repeat an element with different frequency

MATLAB

I have the following values: 
A = [1 2 3 4 5];
And want to use the following to denote frequency: 
B = [1 1 3 3 3];
Is there a way I can do this to yield the following: 
C = [1 2 3 3 3 4 4 4 5 5 5];

Best Answer

You can do the following using 'repelem'. See the following: 
A = [1 2 3 4 5];
B = [1 1 3 3 3];
C = repelem(A, B)
For more information, see the following documentation page: 
https://www.mathworks.com/help/matlab/ref/repelem.html#buqph3a