Problem 60826. Identify Similar Rows in a Matrix Based on Sequence of Non-zero Elements
- The rows must share the same non-zero numbers in the same order.
- The zeros can be ignored but should be at the end of the row.
Solution Stats
Problem Comments
-
3 Comments
I'm not sure I understand your notion of similarity. Suppose we've got rows r1 and r2, and let r1n and r2n denote r1 and r2 with trailing zeros removed. By your first condition, for r1 and r2 we must have that r1n equals r2n. But since the remainder of r1 and r2 is zeros, this implies that r1 and r2 are also equal, yet this is clearly not what the test suite expects.
I don't think that this can be cured by reading the problem description differently either. In particular, your test suite indicates that for a zero matrix, the result should be empty, yet I cannot conceive of a sensible notion of similarity by which the first row is not similar to itself.
I also would like to point out that in your solution template (which does not pass the test suite) what the code does is at odds with what the comments say it does.
Christian, I think that this problem is fundamentally okay, except that test problem #1 has an incorrect result, and it is a bit ambiguous about what the result *should* be in the case that the input in a zero matrix. In the latter case, I think you are right, but since the test of similarity only involves the matrix elements that are not zero, and there are none, I suppose there could be some room for disagreement. Certainly, the only possible correct answers would be either the entire matrix or the empty matrix.
Thanks, William. I'm unsure how the problem description could be understood such that there is ever a case where a row (even an all-zero row) is not similar to itself, but unless and until the author provides clarification we may never know what's intended.
To the author: I would also suggest that when checking whether a matrix is empty, you use isempty(...) rather than isequal(..., []) since the latter also checks the size, and [] is specifically a 0×0 matrix.
Solution Comments
Show commentsProblem Recent Solvers3
Suggested Problems
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!