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'))
draws = sum(strcmp(games, 'D'));
Find common elements in matrix rows
1272 Solvers
Find the peak 3n+1 sequence value
1122 Solvers
701 Solvers
902 Solvers
2732 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!