Suppose I have a vector like: [ 3 2 4 1 3 2...]
I want to obtain a new vector like:
[3 3 3 2 2 4 4 4 4 1 3 3 3 2 2...]
basically every value repeates it's own number of times.
is there a simple vectorized way to do this?
thanks!
v=[ 3 2 4 1 3 2 ]
cell2mat(arrayfun(@(x) x+zeros(1,x), v, 'uni', 0))
% Bruno
A = [ 3 2 4 1 3 2]
A(A==0) = []; % Need to get rid of zeros in the general case.
cs = cumsum(A);
B = zeros(1,cs(end));
B([1 cs(1:end-1)+1]) = 1;
B = A(cumsum(B))
SQ*eUd5Q_QoYRoU^_\f\}YI_`Qoeo=QX]][WvRS`__diQoXo_o^UdvoUQX0
Bruno, Matt Thanks you guys!