Problem 36. Find relatively common elements in matrix rows
Solution Stats
Problem Comments

8 Comments
Tests aren't specifically adapted to this problem. The code for problem 67 (Find common elements in matrix works here).
Absolutely agree with JeanMarie.
Tests is not good enough.
Not sure if the previous commenters have the same issue that I have, but I dislike that this testsuite makes a difference in how the emptymatrix is defined (See also comments for solution 167825).
I would suggest checking isempty' for the relevant solutions.
Ironically, simply including the example from the problem statement in the test suite would reject the current smallest ("best") solutions.
Indeed, the current leading solutions with size 29 yield only elements that exist in ALL of the rows in the matrix!
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))
https://blog.csdn.net/qq_44846756/article/details/116567963
i thought different
The test suit has been updated to check for miscellaneous cases and a reference solution is added.
Solution Comments

2 Comments
I know I have adapted code according to test cases. But was stuck in this one.
This is a great solution!

2 Comments
Don't know why an empty matrix 1by0 is not equal to the empty matrix [].
[] is 0by0. mtimes(ones(1,0), ones(0,1)) equals 0, mtimes([], ones(0,1)) is empty 0by1. This is one of the reasons.

1 Comment
I used exactly the same code as for problem 67.

1 Comment
Nice! But I think you made a mistake in if length(m)==size(x,1), according to the instruction, a number that appears more than half of total rows would be okay.

1 Comment
when x = [1 1 1 1;2 3 4 5;3 6 7 8] it not work

2 Comments
My solution fails on the magic, the wilkonson and the [1;2] inputs.
However, on my own computer each input works as expected.
Anyone has a hint on where I am going wrong?
Found it.
Due to the way the testsuite is setup (using 'isequal'), MATLAB makes a difference between the values "[]" (size [0 0]) and "Empty matrix: 1by0" (size [1 0]), even though they are both considered empty.
Problem Recent Solvers1551
Suggested Problems

293 Solvers

Back to basics 19  character types
251 Solvers

Find the maximum number of decimal places in a set of numbers
1919 Solvers

Given a window, how many subsets of a vector sum positive
831 Solvers

411 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!