I would like to be able to further vectorize the following code to try and remove the for loop:
A = randi(5,1,100);
for X = unique(A)
B(A==X) = sum(randi(17,sum(A==X),X),2);
end
Basically it is summing 1 to 5 (designated by A
) random numbers between 1 and 17, 100 times. This happens multiple times, with B
getting substituted for A
in the following iteration. The number of loops increases exponentially with each step and I need to do 10^9 trials instead of just 100, so I'd like to remove as much as possible. Any help would be appreciated. Thanks!