Issue with finding intersection between randomly generated matrices
Mostra commenti meno recenti
I have two matrices randomly generated A and A_new (subset of A). When I use the intersect command, very surprisingly it negates one of the rows, while identifies the other four rows. Below is the screenshot while trying to debug the issue:

However, when I copy A and A_new directly from the workspace into different variables (A1 and A2 respectively) and use the same intersect command, the result comes out perfect:
A1 = [-17.1747990884382 19.2719049157323 99.6315612404934 % note: A is actually 71-by-3, but here I used only 22-by-3
-10.1200347628603 44.6569202438877 94.7227267967226
58.6115851834664 -9.53770294596646 92.9138476931620
47.0203961819196 -18.8814327228311 87.4170841370532
93.0719877076277 -40.6092086918209 85.2369720823465
62.7067365154531 -40.8222018404139 82.3859521001850
28.4948014516781 24.4091032205797 80.3478942902817
-27.4120788164787 46.4475836126667 80.0165302698221
52.5520137564189 -86.2238156283654 78.0805162946764
34.8647540565998 -78.4903445824848 73.9133775177247
64.6182025041414 -8.02799812625432 71.0037105461384
-74.2010206861346 27.4023369519983 70.4017187841455
13.4165633024713 43.2557370559446 70.1735863347631
79.3294488296403 46.5421363760066 67.5796378292223
71.7027257281106 -99.6206397947143 66.7042052990168
8.66568815370449 86.0343589130021 59.3423113221334
25.6901433887827 -13.4695262062841 58.4318188330688
-39.5611117917563 47.4462315581845 53.9216963646236
-8.49830028866433 -46.7213246886748 49.1592271029911
-74.0052720695440 99.2224561788284 49.0989168204624
-43.0371001304189 58.8076794390692 46.2077865058290
78.7271494784465 95.8905249403584 45.4459816955421];
A2 = [93.0719877076277 -40.6092086918209 85.2369720823465
79.3294488296403 46.5421363760066 67.5796378292223
8.66568815370449 86.0343589130021 59.3423113221334
-74.0052720695440 99.2224561788284 49.0989168204624
78.7271494784465 95.8905249403584 45.4459816955421];
[~,idx2,~] = intersect(A1,A2,'rows');
idx2 =
20
16
22
14
5
I wonder why this discrepency? I thought of using rounding option and it works for this random set, however, messes up some other random sets. Any suggestion to fix the issue would be highly appreciated. I am really confused.
Thanks in advance, and sorry for the long question.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!