Translate code to parallel computing
Show older comments
Hello, everybody
I just would like to ask if somebody could help me to "translate" the follow code to turn it able to run using the parallel computing toolbox:
It is part of one study about lottery, and it is taking too much time to process.
% In this lottery, 15 numbers out of 25 (1 to 25) are drawn. You can win
% specific prizes if you match 11 numbers, or 12 numbers, or 13 numbers,
% or 14 numbers, or 15 numbers.
b = 0; v = 0;
v = 1:25;
combinations = nchoosek(v,15); % matrix with 3268760 lines with all
% combinations possible to 15 numbers
% chosen between 1 and 25.
lottery = randi(25,2400,15); %simulates 2400 draws for this lottery
number_of_combinations = size(combinations,1); %3268760
number_of_draws = size(lottery,1); %2400
registers = zeros(number_of_combinations,7);
for b = 1:number_of_combinations
registers(b,1) = b;
end
won15 = 0; won14 = 0; won13 = 0; won12 = 0; won11 = 0;
hit = 0;
i = 0; j1 = 0; j2 = 0; k = 0;
for i = 1:number_of_combinations
for k = 1:number_of_draws
for j1 = 1:15
for j2 = 1:15
if combinations(i,j1) == lottery(k,j2) %check how many times each combinations
% won some prize considering all 2400 draws
hit = hit+1;
end
end
if hit == 15
won15 = won15+1;
registers(i,2) = k; %won the biggest prize in what draw?
registers(i,3) = won15; %won with 15 numbers how many times?
end
if hit == 14
won14 = won14+1;
registers(i,4) = won14; %won with 14 numbers how many times?
end
if hit == 13
won13 = won13+1;
registers(i,5) = won13; %won with 13 numbers how many times?
end
if hit == 12
won12 = won12+1;
registers(i,6) = won12; %won with 12 numbers how many times?
end
if hit == 11
won11 = won11+1;
registers(i,7) = won11; %won with 11 numbers how many times?
end
end
hit = 0;
end
won15 = 0;
won14 = 0;
won13 = 0;
won12 = 0;
won11 = 0;
end
In this code I check how many times each combination possible won considering all 2400 draws.
thanks in advance,
Paulo
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Report Generator in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!