MATLAB Answers


Finding the Euclidean Distance

Asked by Pat
on 29 Dec 2012
Accepted Answer by Matt J
I have values as
data2 = 
      [20x480 double]    [20x480 double]    [20x480 double]    [20x480 double]
      { 1x8   cell  }    { 1x8   cell  }    { 1x8   cell  }    { 1x8   cell  }
data1 = 
      [20x480 double]   
      { 1x8   cell  } 
i want to match data2 and data1 by euclidean distance and if same values are present i want to display it,plz help

  1 Comment

Matt J
on 29 Dec 2012

What's in the 1x8 cells?

What do you want displayed? The data? The column numbers of data2 which agree with data1?

When are the values considered "the same"? When the Euclidean distance = 0 precisely or is there some tolerance>0? If the tolerance=0, why care about the Euclidean distance at all? Why not just use ISEQUAL, as in my Answer below?


No products are associated with this question.

1 Answer

Answer by Matt J
on 29 Dec 2012
 Accepted answer

 find(arrayfun(@(i) isequal(data2(:,i),data1), 1:size(data2,2) )),


Matt J
on 2 Jan 2013


data1=data2 is not a valid example of your original problem description. In your problem as you originally posted it, data1 had only one column. When I modify your example as follows, I get the expected result

           num2cell(ones(1,8)), num2cell(ones(1,8))};
    find(arrayfun(@(i) isequal(data2(:,i),data1), 1:size(data2,2) ))
      ans =

If this is not what you want, edit your question clarifying the form of the data and also, include a numerical example of desired input and output.

on 3 Jan 2013

if data1 has different values i get empty matrix

i want to display data is present ,how can i check the answer if it is empty matrix or not and display it

so how i can display it as "data is present".


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!