Counting an element in Matrix
이전 댓글 표시
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.
답변 (1개)
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!