MATLAB: How to make new elements (columns) in a vector (matrix) based on the each value of this vector

matrixonesvector

How to expand each element of a vector with ones based on the value of this element.
For example, if vector is: A=[4 2 3 …], then the new vector will be: C=[1 1 1 1 1 1 1 1 1 …]. So, the number of how many ones depend on the value of each element of this vector A.
Thanks, Khalid

Best Answer

A=[4 2 3]
C=ones(1,sum(A))