필터 지우기
필터 지우기

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.

채택된 답변

Star Strider
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개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by