How to calculate euclidean distance for 3 vectors using matlab

조회 수: 4 (최근 30일)
krishnasri
krishnasri 2015년 3월 16일
댓글: krishnasri 2015년 4월 19일
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
Andrew Newell
Andrew Newell 2015년 3월 16일
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 2015년 3월 25일
편집: Andrew Newell 2015년 3월 25일
yes exactly that is what i meant, can you please help me with the code??

댓글을 달려면 로그인하십시오.

채택된 답변

Andrew Newell
Andrew Newell 2015년 3월 25일
편집: Andrew Newell 2015년 4월 15일
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
Andrew Newell
Andrew Newell 2015년 4월 18일
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.
krishnasri
krishnasri 2015년 4월 19일
Okay thanq got it. But what for are we using distance(I) = norm(sheetdiff(I,:))?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by