Cody

Problem 67. Find common elements in matrix rows

Solution 1879674

Submitted on 20 Jul 2019
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 = []; y_correct = []; assert(isequal(common_by_row(x),y_correct))

t = 0×1 empty double column vector

Undefined function or variable 's'. Error in common_by_row (line 6) s Error in Test1 (line 3) assert(isequal(common_by_row(x),y_correct))

2   Fail
x = [1e100; 1e100]; y_correct = [1e100]; assert(isequal(common_by_row(x),y_correct))

t = 1.0000e+100

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in common_by_row (line 4) s(i)= find(x==t(i)); Error in Test2 (line 3) assert(isequal(common_by_row(x),y_correct))

3   Fail
x = [1; 2]; y_correct = []; assert(isequal(common_by_row(x),y_correct))

t = 1 2 s = 1 2

Output argument "y" (and maybe others) not assigned during call to "common_by_row". Error in Test3 (line 3) assert(isequal(common_by_row(x),y_correct))

4   Fail
x = ones(10); y_correct = [1]; assert(isequal(common_by_row(x),y_correct))

t = 1

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in common_by_row (line 4) s(i)= find(x==t(i)); Error in Test4 (line 3) assert(isequal(common_by_row(x),y_correct))

5   Fail
x = magic(10); y_correct = []; assert(isequal(common_by_row(x),y_correct))

t = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 s = Columns 1 through 30 21 35 44 3 17 18 22 31 45 9 10 19 28 32 41 42 6 20 24 33 34 43 7 16 25 76 90 94 58 67 Columns 31 through 60 68 77 86 95 59 60 69 78 87 91 92 56 70 79 88 89 93 57 66 80 71 85 99 53 62 63 72 81 100 54 Columns 61 through 90 55 64 73 82 96 97 51 65 74 83 84 98 52 61 75 26 40 49 8 12 13 27 36 50 4 5 14 23 37 46 Columns 91 through 100 47 1 15 29 38 39 48 2 11 30

Output argument "y" (and maybe others) not assigned during call to "common_by_row". Error in Test5 (line 3) assert(isequal(common_by_row(x),y_correct))

6   Fail
x = wilkinson(9); y_correct = [0 1]; assert(isequal(common_by_row(x),y_correct))

t = 0 1 2 3 4

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in common_by_row (line 4) s(i)= find(x==t(i)); Error in Test6 (line 3) assert(isequal(common_by_row(x),y_correct))

7   Fail
x = [3 -2 1 NaN; NaN 0 -2 3]; y_correct = [-2 3]; assert(isequal(common_by_row(x),y_correct))

t = -2 0 1 3 NaN NaN

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in common_by_row (line 4) s(i)= find(x==t(i)); Error in Test7 (line 3) assert(isequal(common_by_row(x),y_correct))