How to calculate euclidean distance for 3 vectors using matlab

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

2 comentarios

Judging by your title, you actually want to find the distance between column 1 of your first sheet and column 1 of the other sheets; and ditto for columns 2 and 3. Correct?
krishnasri
krishnasri el 25 de Mzo. de 2015
Editada: Andrew Newell el 25 de Mzo. de 2015
yes exactly that is what i meant, can you please help me with the code??

Iniciar sesión para comentar.

 Respuesta aceptada

Andrew Newell
Andrew Newell el 25 de Mzo. de 2015
Editada: Andrew Newell el 15 de Abr. de 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,:));
end
Now you'll have to put this inside another loop where you look at one sheet at a time.

7 comentarios

in each sheet i have a 60x3 values, after calculating euclidean distance, the result is again a 60x3, but when we calculate euclidean distance it should result in 60x1?
Andrew Newell
Andrew Newell el 15 de Abr. de 2015
Editada: Andrew Newell el 15 de Abr. de 2015
Sorry, I must have been distracted when I provided that code. It doesn't work even for the problem I thought you were asking. But you are really comparing rows, not columns. I have corrected the code in the answer.
My Question actually is that, I am trying to calculate euclidean distance between values in two different excel sheets.These two sheets contains 60x3 values. After calculating the euclidean distance the result is also a 60x3, whereas it has to be 60x1?
Have you tried the corrected version?
krishnasri
krishnasri el 17 de Abr. de 2015
Editada: Andrew Newell el 18 de Abr. de 2015
yes even the corrected version is resulting in a 60x3 values. here is the code which i tried.
close all;
clear all;
clc;
sheet0= xlsread('15N.xls');
sheet1= xlsread('15A.xls');
sheetdiff = sheet1-sheet0;
npoints = size(sheet0,1);
distance = zeros(npoints,1);
for I = 1:npoints
distance(I) = norm(sheetdiff(I,:));
end
xlswrite('15Aed',sheetdiff);
Judging by the last line, you are treating sheetdiff as the answer. It isn't. The real answer is distance, which has dimensions npoints x 1.
Okay thanq got it. But what for are we using distance(I) = norm(sheetdiff(I,:))?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 16 de Mzo. de 2015

Comentada:

el 19 de Abr. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by