Cody

Problem 44671. find number of times of occurrence of the most frequent number in a row vector

Solution 1627119

Submitted on 13 Sep 2018
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   Fail
x =[2 3 3 3 5 3 3 5 5 5 5 5 5]; y_correct = 7; assert(isequal(num_mode(x),y_correct))

ux = 2 3 5 nx = 0 0 0 nx = 1×13 logical array 1 0 0 0 0 0 0 0 0 0 0 0 0 nx = 1×13 logical array 0 1 1 1 0 1 1 0 0 0 0 0 0 nx = 1×13 logical array 0 0 0 0 1 0 0 1 1 1 1 1 1 idx = 1×0 empty double row vector

Error using == Matrix dimensions must agree. Error in num_mode (line 8) y = sum(x==ux(idx)) Error in Test1 (line 3) assert(isequal(num_mode(x),y_correct))

2   Fail
x =[8 8]; y_correct = 2; assert(isequal(num_mode(x),y_correct))

ux = 8 nx = 0 nx = 1×2 logical array 1 1 idx = 1×0 empty double row vector

Error using == Matrix dimensions must agree. Error in num_mode (line 8) y = sum(x==ux(idx)) Error in Test2 (line 3) assert(isequal(num_mode(x),y_correct))