Problem 36. Find relatively common elements in matrix rows
You want to find all elements that exist in greater than 50% of the rows in the matrix.
For example, given
A =
1 2 3 5
9 2 5 9
3 2 5 8
1 2 1 5
5 1 3 2
the answer would be the row vector
[1 2 3 5]
since each of these appears three or more times in the rows of matrix A. Elements should be returned sorted ascending.
Note there is no guarantee that there are any such elements; if there are none, the routine should return the empty set. Also, the matrix might contain repeats, very large or very small numbers, or NaNs (though NaN should not be treated as a number to be returned in the output).
Solution Stats
Problem Comments
-
8 Comments
Show
5 older comments
Simon Thomas
on 20 Nov 2017
This needs another test case.
Many would fail this:
%%
x = [1 1 1 1;2 3 4 5;3 6 7 8];
y_correct = [3];
assert(isequal(common_by_row(x),y_correct))
arsenic 陈
on 10 May 2021
https://blog.csdn.net/qq_44846756/article/details/116567963
i thought different
Dyuman Joshi
on 25 Aug 2021
The test suit has been updated to check for miscellaneous cases and a reference solution is added.
Solution Comments
Show commentsProblem Recent Solvers2087
Suggested Problems
-
What is the next step in Conway's Life?
655 Solvers
-
276 Solvers
-
417 Solvers
-
520 Solvers
-
Is this is a Tic Tac Toe X Win?
513 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!