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 Solvers38
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15814 Solvers
-
1780 Solvers
-
Find the sides of an isosceles triangle when given its area and height from its base to apex
2218 Solvers
-
the average value of the elements
2400 Solvers
-
Determine if Input is Oddish or Evenish (Odd/Even Sum of Digits)
331 Solvers
More from this Author35
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!