Finding rows where the first column values are equal
15 views (last 30 days)
Show older comments
Array A:
13453 10359 9955
5257 5299 5258
5849 3644 5848
5397 7230 5396
17132 17130 17118
4767 4768 4770
8291 8292 8316
3191 3190 15970
13389 14409 14410
14840 13022 13021
Array B:
13453 12292 9955 10359
6805 3039 3012 3011
2005 8087 2394 17740
5257 5258 5299 2012
6309 6290 6310 6289
5849 5811 5848 3644
5397 7230 8425 5396
4775 4760 6529 1118
17132 17130 13938 17118
4767 4791 4770 4768
8291 8292 5145 8316
3191 3190 14432 15970
10539 14895 9170 10540
13389 14409 9927 14410
14840 14387 13021 13022
Expected output: Indices of rows in Array B where the first column value is the same as Array A:
1
4
6
7
9
10
11
12
14
15
When I try to use ismember, I get an error that "arrays have incompatible sizes".
x = find (B(:,1) == A (:,1));
0 Comments
Accepted Answer
Arif Hoq
on 7 Mar 2022
Edited: Arif Hoq
on 7 Mar 2022
A=[13453 10359 9955
5257 5299 5258
5849 3644 5848
5397 7230 5396
17132 17130 17118
4767 4768 4770
8291 8292 8316
3191 3190 15970
13389 14409 14410
14840 13022 13021];
B=[13453 12292 9955 10359
6805 3039 3012 3011
2005 8087 2394 17740
5257 5258 5299 2012
6309 6290 6310 6289
5849 5811 5848 3644
5397 7230 8425 5396
4775 4760 6529 1118
17132 17130 13938 17118
4767 4791 4770 4768
8291 8292 5145 8316
3191 3190 14432 15970
10539 14895 9170 10540
13389 14409 9927 14410
14840 14387 13021 13022];
Output=find(ismember(B(:,1),A(:,1)))
16 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!