How to calculate euclidean distance for 3 vectors using matlab

10 views (last 30 days)
krishnasri on 16 Mar 2015
Commented: krishnasri on 19 Apr 2015
Say suppose I have 83*3 matrix in an excel sheet and similarly I have 600 sheets with 83*3 matrix/data those vectors are x,y,z and I need to calculate distance between first and second data set/excel sheet date, second and third,third and fourth ...till 600
some one help to solve using MATLAB code
krishnasri on 25 Mar 2015
yes exactly that is what i meant, can you please help me with the code??

Sign in to comment.

Accepted Answer

Andrew Newell
Andrew Newell on 25 Mar 2015
Edited: Andrew Newell on 15 Apr 2015
You can find the Euclidean distance between two vectors v1 and v2 using norm:
distance = norm(v1-v2);
I don't know how you are importing the sheets, so let's just look at two sheets, with your initial matrix being sheet0 and the other sheets being numbered 1, 2, ...
(Edited to correct error)
sheetdiff = sheet1-sheet0;
npoints = size(sheet0,1);
distance = zeros(npoints,1);
for I = 1:npoints
distance(I) = norm(sheetdiff(I,:));
Now you'll have to put this inside another loop where you look at one sheet at a time.
krishnasri on 19 Apr 2015
Okay thanq got it. But what for are we using distance(I) = norm(sheetdiff(I,:))?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!