Element-wise array replication according to a count [duplicate]
Here’s one way I like to accomplish this: >> index = zeros(1,sum(rep)); >> index(cumsum([1 rep(1:end-1)])) = 1; index = 1 0 1 0 0 1 1 0 0 0 0 >> index = cumsum(index) index = 1 1 2 2 2 3 4 4 4 4 4 >> vv = v(index) vv = 3 3 … Read more