Compare each row of array, then return the number of rows that are equal
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
monkey_matlab
il 20 Nov 2016
Risposto: Star Strider
il 20 Nov 2016
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 Commenti
Risposta accettata
Star Strider
il 20 Nov 2016
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!