number of times a value appears in an array or vector

24 views (last 30 days)
x = [1,2,3,4,5,6,7,8,9,10,10,10,10];
PlayersHand = [x(randi(length(x))),x(randi(length(x)))]
DealersHand = [x(randi(length(x)))]
I need something to tell me how many 1's appear in PlayersHand each time I run it
Thanks.

Accepted Answer

Adam Danz
Adam Danz on 27 Feb 2020
I need something to tell me how many 1's appear in PlayersHand each time I run it
count = sum(PlayersHand(:)==1);

More Answers (0)

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!