I want to create a vector containing the group identifier for each element from a vector containing the number of elements in each group.
Example:
E = [2 3 4]'
I am looking for a vector as follows:
I = [1 1 2 2 2 3 3 3 3]
I found one solution involving a loop:
I = [];
for e=1:size(E,1),
I = [I ; e*ones(E(e),1)];
end
But this doesn't seem very elegant. Any advice for improvements are welcome.