Asked by Théodore Keller
on 16 Jul 2019

Hello,

I have two sets of matched points (matchedPoints1 and matchedPoints2, the size is 142x1 and the type is SURFPoints) and I want to calculate the distance between them. I tried the function pdist2() like this :

dist_matchedPoints=pdist2(matchedPoints1,matchedPoints2,'euclidean');

But I got the following error :

Error using cast

Unsupported data type for conversion: 'double'.

Error in pdist2 (line 250)

X = cast(X,outClass);

I don't really understand the meaning of this error message so can somebody help me to solve this problem ?

Thanks a lot.

Answer by Adam Danz
on 16 Jul 2019

Edited by Adam Danz
on 16 Jul 2019

Accepted Answer

The (x,y) point locations are stored in the "Locations" property of a SURFpoints object. If you are calculating the distance between matchedPoints1(n) and matchedPoints2(n), follow this example

%matchedPoints1 & matchedPoints2 are SURFpoints objects

distanceFcn = @(x1,x2,y1,y2)sqrt((x2-x1).^2 + (y2-y1).^2); %distance function

d = distanceFcn( ...

matchedPoints1.Location(:,1),...

matchedPoints2.Location(:,1),...

matchedPoints1.Location(:,2),...

matchedPoints2.Location(:,2));

% d(n) is the distance between matchPoints1.Location(n) and matchPoints2.Location(n)

To calculate the pairwise distance,

d = pdist2(matchedPoints1.Location,matchedPoints2.Location,'euclidean')

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Adam Danz (view profile)

## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/472006-calculate-the-distance-between-matched-points#comment_725138

## Théodore Keller (view profile)

## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/472006-calculate-the-distance-between-matched-points#comment_725143

## Adam Danz (view profile)

## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/472006-calculate-the-distance-between-matched-points#comment_725144

## Théodore Keller (view profile)

## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/472006-calculate-the-distance-between-matched-points#comment_725149

## Adam Danz (view profile)

## Direct link to this comment

https://uk.mathworks.com/matlabcentral/answers/472006-calculate-the-distance-between-matched-points#comment_725164

Sign in to comment.