Compare each row of array, then return the number of rows that are equal
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, I was trying to compare each row, one by one, and then return the number of rows that are equal.
For example, for the arrays A and B:
A = [1;1;2;3];
B = [2;1;1;3];
The rows that are equal to each other = 2...that is, rows 2 and 4 are equal. I tried the command:
all(A()==B())
but got the ans = 0.
Any help is appreciated.
댓글 수: 0
채택된 답변
Star Strider
2016년 11월 20일
Try this:
A = [1;1;2;3];
B = [2;1;1;3];
C = [A, B];
Equal_Rows = find(diff(C,[],2) == 0)
Equal_Rows =
2
4
NOTE — This only reliably works with integers. For floating point numbers, especially those that are the result of calculations, you would need to incorporate a tolerance, probably involving a ‘greater-than-or-equal to’ and a ‘less-than-or-equal-to’ condition. See Why is 0.3 - 0.2 - 0.1 (or similar) not equal to zero? for an explanation.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!