Check if the multiple 1x2 arrays contained within a 4x2 array exist within a larger 10x2 array

1 view (last 30 days)
4x2 array a1 below. 10x2 array b1 below. I want to know if the 4 1x2 arrays [1;5], [5;4], [4;7], and [3;1] all exist in b1, irregardless of the order.
The code below is an example of code that should work.
a1= [1, 5, 4, 3; 3, 4, 7, 1]
a1 = 2×4
1 5 4 3 3 4 7 1
b1= [5,4,1,3,7,1,9,5,8,3; 4,7,3,1,5,6,3,9,5,3]
b1 = 2×10
5 4 1 3 7 1 9 5 8 3 4 7 3 1 5 6 3 9 5 3

Answers (1)

Dyuman Joshi
Dyuman Joshi on 22 Nov 2023
a1 = [1, 5, 4, 3; 3, 4, 7, 1]
a1 = 2×4
1 5 4 3 3 4 7 1
b1 = [5,4,1,3,7,1,9,5,8,3; 4,7,3,1,5,6,3,9,5,3]
b1 = 2×10
5 4 1 3 7 1 9 5 8 3 4 7 3 1 5 6 3 9 5 3
[out, idx] = ismember(a1.', b1.', 'rows')
out = 4×1 logical array
1 1 1 1
idx = 4×1
3 1 2 4

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!