Given a matrix, find all elements that exist in every row.
For example, given
A =
1 2 3 5
9 2 5 9
3 2 5 9
1 2 1 5
5 1 3 2
the answer would be the vector '2 5'. 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 NaNs, repeats, or very large or very small elements.
Solution Stats
Problem Comments
6 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers2713
Suggested Problems
-
Given two arrays, find the maximum overlap
1722 Solvers
-
Back to basics 21 - Matrix replicating
1796 Solvers
-
Set the array elements whose value is 13 to 0
1438 Solvers
-
find the maximum element of the matrix
537 Solvers
-
16427 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!
Any version of "empty" should be acceptable as correct.
For example, intersect can output a 1x0 empty matrix. That should be allowed.
Somehow the assert is triggered if the function returns a [] that has been "sorted".
If I include that code
if ~isempty(y)
y = sort(unique(y));
end
no assert is triggered. Seem strange!
How can the leading solution be 0??
Following many comments, the Test Suite should be amended to check for an empty output vector using "isempty", rather testing for equality to []. Such an amendment is appropriate, and would not break any of the previously submitted successful solutions. —DIV
Test cases with an empty result now test against isempty().
intresting