Cody

Problem 44480. The average of the second largest values

Solution 1738248

Submitted on 27 Feb 2019 by Martin C.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
x = [1 2 3 4;8 7 6 5;9 0 1 4]; y_correct = (3 + 7 + 4) / 3; assert(isequal(ave_2ndM(x),y_correct))

le = 4 s = 0 m = 4 I = 4 c = 1 2 3 s = 3 m = 8 I = 1 c = 7 6 5 s = 10 m = 9 I = 1 c = 0 1 4 s = 14 y = 4.6667

2   Pass
x = [2 4 ;5 9; 0 5;88 52]; y_correct = (2 + 5 + 0 + 52) / 4; assert(isequal(ave_2ndM(x),y_correct))

le = 4 s = 0 m = 4 I = 2 c = 2 s = 2 m = 9 I = 2 c = 5 s = 7 m = 5 I = 2 c = 0 s = 7 m = 88 I = 1 c = 52 s = 59 y = 14.7500

3   Pass
x = [97 93 68 58 24 74 55 49 40 24 63 53 46 37 19]; y_correct = (93 + 55 + 53) / 3; assert(isequal(ave_2ndM(x),y_correct))

le = 5 s = 0 m = 97 I = 1 c = 93 68 58 24 s = 93 m = 74 I = 1 c = 55 49 40 24 s = 148 m = 63 I = 1 c = 53 46 37 19 s = 201 y = 67

4   Pass
x = [ 82 65 14 40 44 73 81 18 53 2 15 46 40 42 99 66 44 84 66 17 52 83 81 63 11 98 9 7 30 38]; y_correct = 61.5; assert(isequal(ave_2ndM(x),y_correct))

le = 6 s = 0 m = 82 I = 1 c = 65 14 40 44 s = 65 m = 81 I = 2 c = 73 18 53 2 s = 138 m = 99 I = 5 c = 15 46 40 42 s = 184 m = 84 I = 3 c = 66 44 66 17 s = 250 m = 83 I = 2 c = 52 81 63 11 s = 331 m = 98 I = 1 c = 9 7 30 38 s = 369 y = 61.5000

Community Treasure Hunt

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

Start Hunting!