I have a variable distr=[0 3 1 0 2];
, and I have a variable full
which should contrain distr(i)
times i
, for all i
.
In this example, i want:
full=[2 2 2 3 5 5];
because distr(2)=3
, therefore 3x 2
, and so on.
Of course I can do it in a for
-loop:
full=zeros([1,sum(distr)]);
cc=1;
for i=1:length(distr)
curr=distr(i);
full(cc:cc+curr-1)=i*ones([1,curr]);
cc=cc+curr;
end
but that is very slow. Do you know of a fast way, using MATLAB's awesome array-oriented style? Thanks!