3

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.

1 Answer 1

4

'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)];
Sign up to request clarification or add additional context in comments.

1 Comment

That did the trick, thanks. I really should have read the help intersect more closely...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.