Given a vector s of strings representing a batter's individual innings scores, return their career statistics as a 4-element (numeric) row vector representing: average, half-centuries, centuries, and ducks. The strings will be in the form of a number ("42") or a number with an asterisk ("42*") to represent "not-out".
- Batting average is defined as total runs divided by number of dismissals (ie number of innings - number of not-outs).
- Half-centuries is the number of scores from 50 to 99 (whether out or not-out)
- Centuries is the number of scores greater than 99 (whether out or not-out)
- Ducks is the number of scores of 0 out (0* should not be counted)
For example:
s = ["53";"163*";"6";"186";"147*";"0";"89*";"0*"];
stats = battingstats(s)
stats =
161 2 3 1
In this case, the batter has a total of sum([53 163 6 186 147 0 89 0]) = 644 runs from 4 completed innings (8 innings - 4 not-outs). Hence their average is 644/4 = 161. They have two half-centuries (53 and 89*), three centuries (163*, 186, 147*), and one duck (0 - the 0* does not count as a duck).
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers35
Suggested Problems
-
Determine Whether an array is empty
808 Solvers
-
Pernicious Anniversary Problem
835 Solvers
-
6292 Solvers
-
Calculate the mean of each half of a matrix
669 Solvers
-
Convert Volume Mixing Ratio to Density
107 Solvers
More from this Author33
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!