Counting an element in Matrix

1 view (last 30 days)
John
John on 3 Apr 2014
Commented: John on 3 Apr 2014
I'm trying to simulate Fantasy 5 lotto and count the actual probability of each winnings (5 out of 5),(4 out of 5), and so on. I have this big Matrix of 600000 rows and 5 columns. I already simulated it and generated a quick pick to compare and see if I have a match on my simulated Fantasy 5 lotto.
% Simulation of Fantasy 5
% uses arrayfun to generate thousands of randperm
% uses cell2mat to display result
lotto = arrayfun(@(x)randperm(39,5),(1:600000)','UniformOutput',0);
display = cell2mat(lotto)
%Generate a random quick pick
quick = randperm(39,5)
%use ismember to determine if quick's results matches with simulated
%lotto results
matches = ismember(display,quick)
Now I have this 600000 rows and 5 columns of 0 zeroes and ones. I want to count the ones on each row and display how many ones are in each row. I tries using sum but it only counts the ones on each columns.

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 3 Apr 2014
sum(A,2)

Categories

Find more on Creating and Concatenating Matrices 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!