Reputation: 8190
I have two arrays in matlab representing tracked points by two different methods. In each array the first column contains the frame number, and columns two and three are the x, y coordinates. The tracks don't necessarily start or finish at the same frame, but I want to compare the distances between tracks for any common frames.
My input data is something along the lines of:
d1 = d2 =
[ 130 50 20; [ 128 48 17;
131 50 21; 129 52 19;
... ...
195 70 36 ] 180 65 34 ]
I can find intersecting frame numbers using
commonFrames = intersect(d1(:,1), d2(:,1));
but I'm stuck on how to align these arrays (preferably without a for loop)?
I'd looking for an output along the lines of [frameNumber x1 y1 x2 y2]
where x1, y1 are values from frame frameNumber of array d1, and x2, y2 are values from frame frameNumber of array d2.
Upvotes: 3
Views: 2243
Reputation: 1241
'intersect' function has two additional output values: indices of common values in input arrays.
Your script can be following:
[commonFrames,ia,ib] = intersect(d1(:,1), d2(:,1));
commonData = [commonFrames d1(ia,2:3) d2(ib,2:3)];
Upvotes: 4