iteratorr
iteratorr

Reputation: 149

comparing numbers in matlab

I am trying to classify some data based on euclidean distances in matlab the only problem is that matlab is giving me numbers that look like these as distances

0 + 4.9713i
0 + 7.8858i

 num1<num2  
 num2<num1 

both return 0. how is this possible?

Upvotes: 2

Views: 2082

Answers (2)

MatlabDoug
MatlabDoug

Reputation: 5714

Numbers with real and imaginary parts are not orderable. Maybe you mean order by distance from origin?

Upvotes: 1

Jonas
Jonas

Reputation: 74940

The numbers you're getting are imaginary numbers. You should never obtain imaginary numbers when you calculate Euclidean distances.

Check that your Euclidean distances are correct, such as

distance=sqrt(deltaX.^2 + deltaY.^2)

If you're really sure that your distances should be complex numbers, make the comparison using e.g. the norm, i.e.

norm(num2) > norm(num1)

This evaluates to true for me.

Upvotes: 3

Related Questions