# Check for coordinate pairs matches in .mat file

5 views (last 30 days)
rbharrs on 25 Oct 2021
Commented: Star Strider on 25 Oct 2021
I have a .mat file with with four variables : target, time, x and y. Given a pair of x and y detection on a object tracker, I want to check if the pair appears in the file. How do I iterate through this variable to find a matching pair? I don't need the index, just a true of false of whether the match exists or not.
Pseudocode:
isAMatch = -1
if exist(x,y)
isAMatch = 1
else
isAMatch =0
end

Star Strider on 25 Oct 2021
If I understand the problem correctly, the ismember function may be appropriate —
List = randi(9, 10, 2)
List = 10×2
7 1 6 8 5 4 6 1 3 8 1 8 9 5 5 5 4 1 4 1
toMatch = randi(9, 1, 2)
toMatch = 1×2
6 1
matchedRows = ismember(toMatch, List, 'rows')
matchedRows = logical
1
numberMatched = nnz(matchedRows)
numberMatched = 1
.
Star Strider on 25 Oct 2021
My pleasure!
Probably something like this (since I have no idea what the data are) —
yourMatrix = randi(9,10,4)
yourMatrix = 10×4
1 9 5 7 5 4 3 1 9 7 9 2 5 6 2 7 6 1 4 8 1 8 7 2 4 4 2 8 8 4 2 5 8 1 3 3 8 8 7 3
toMatch = yourMatrix(:,[1 2])
toMatch = 10×2
1 9 5 4 9 7 5 6 6 1 1 8 4 4 8 4 8 1 8 8
This should work without changing anything other than the ‘yourMatrix’ variable name in ‘toMatch’.
.

Ive J on 25 Oct 2021
Assuming both x and y are vectors of same length, this might work:
x = randi([0 5], 10, 1);
y = randi([0 5], 10, 1);
myPairedXY = [2 3]; % i.e. x == 2 and y == 3
isMatched = any(x == myPairedXY(1) & y == myPairedXY(2))
isMatched = logical
0

### Community Treasure Hunt

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

Start Hunting!