I have an array freq
with frequencies and another one val
with values.
val =[1 3 5 7];
freq=[2 3 3 2];
I want to get the array result
.
result=[1 1 3 3 3 5 5 5 7 7];
One of the methods I've tried to get result
is:
freq=[2 3 3 2];
val=[1 3 5 7];
result=[];
for i=1:length(val);
result=[result repmat(val(i),1,freq(i))];
end
It works, but with large arrays I expect some performance gain if I get rid of the for
-loop. Is there any built in function for this? How would you calculate result
for large arrays?