function draws = how_many_draws(games)
draws=sum(count(games,'D'));
end
Can someone help? I'm trying to learn how to use cellfun and I don't understand it completely.
Here's one way you can use cellfun to solve this problem. I made an anonymous function called isDraw.
isDraw = @(letter) letter=='D'
d = cellfun(isDraw,games)
draws = sum(d)
Use contains to check how many elements == 'D', then sum
draws = sum(contains(games,'D'))
Select every other element of a vector
20357 Solvers
Number of 1s in a binary string
2826 Solvers
The Answer to Life, the Universe, and Everything
383 Solvers
Output any real number that is neither positive nor negative
316 Solvers
Determine the number of odd integers in a vector
435 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!