이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
euclidean distance calculation for values from excel sheet
조회 수: 4 (최근 30일)
이전 댓글 표시
krishnasri
2015년 3월 26일
sir, I have values in an excel sheet, which contains 60x3 values, they are x,y,z cordinates for all the 60 points.Now I need to find out the distance : |d(i)|=sqrt((x(k)-x(j))^2+(y(k)-y(j))^2+(z(k)-z(j)^2)), where i=1:60 , j,k are end points of the line segment under consideration, i.e., between these 60 points line segments are considered, for which this distance we are calculating. So j,k can be j=1:59 and k=2:60..
Can you please help me with the code...
댓글 수: 22
Jan
2015년 3월 26일
Please ask more precise: Why do you want to do this in Matlab and not in Excel directly? Are you able to import the file already or is this a part of the problem. Did you try to solve this by simple loops already? What did you try at all? Which problems occurred?
krishnasri
2015년 3월 27일
I have all the values, i.e.,60x3 values in excel sheet, i'll import those values into matlab using xlsread. for i=1:60 for j=1:59 for k=2:60 |d(i)|=sqrt((x(k)-x(j))^2+(y(k)-y(j))^2+(z(k)-z(j)^2)),
I've to find out this distance,. from these 60 points i've to find out the distance between these 60 points, for which the above formula has to be used.. When i read values from excel sheet how will i assign that 1st whole coloumn's values are x values and 2nd coloumn values are y values and 3rd coloumn values are z values.
dpb
2015년 3월 27일
Use pdist and it does the assumption for you automagically. If you don't have the Stat Toolbox still just use x(:,1), x(:,2), x(:,3) to refer to the three columns.
See the "Getting Started" section in the documentation and work thru the examples given on how Matlab works with arrays and the colon (:) operator...
krishnasri
2015년 3월 28일
When i am using pdist, clear all; close all; clc; Data = xlsread('A_ed.xls'); D = pdist(Data,'euclidean'); xlswrite('A_norm.xlsx',D,'sheet1');
The values getting copied into excel sheet as 1 single row. I am not able to understand it.. The values are starting from A to BPB in excel sheet
krishnasri
2015년 3월 30일
Can you please tell me how to angle vectors between two line segments in 3D space ,i.e., each point will be having x,y,z cordinates....
Image Analyst
2015년 3월 30일
What does that mean? What does it mean "to angle" a line segment with 2 endpoints in 3D space? Do you want the Euler angles? To you want to change the orientation (Euler angles)? Why are there two line segments? Do you somehow want some kind of angles that describe the location and orientation differences between the two? If so, why? What's the use case?
dpb
2015년 3월 30일
pdist returns a 1D vector per the doc. See
doc squareform
for converting that into a symmetric square array.
I don't understand the second query, sorry...
krishnasri
2015년 3월 31일
Okay thanq for helping me find out euclidean distance. My second query was that, how can i find out the angle between any two lines using the cos inverse, for these lines their end points are only known.
krishnasri
2015년 3월 31일
when i used pdist and when i calculated manually, the values were not matching There was a lot of variation in the values obtained. I calculated using the formula: d(i)=sqrt((x(k)-x(j))^2+(y(k)-y(j))^2+(z(k)-z(j)^2)). Can you please help me..
dpb
2015년 3월 31일
"when i used pdist and when i calculated manually, the values were not matching..."
>> xyz=rand(3); % some random data sample coordinates
>> squareform(pdist(xyz))
ans =
0 0.2374 0.2435
0.2374 0 0.2397
0.2435 0.2397 0
>> del=diff(xyz); % compute differences vertically 2-1, 3-2
>> sqrt(dot(del,del,2)) % euclidean distance between those two
ans =
0.2374
0.2397
>>
NB: This is same as 1-2 and 2-3 from pdist; you can confirm that 1-3 is same as well.
dpb
2015년 3월 31일
편집: dpb
2015년 4월 1일
Oh, and on your question re: the angles; I see nothing better than writing an anonymous function and using nchoosek(1:length(x),2) to generate the list of pairwise indices of the two vectors pairwise as inputs to evaluate the expression. You can write
theta=acos(sqrt(dot(a,b)/{|a||b|}))
in terms of the two indices for vectors a and b to compute the expression.
krishnasri
2015년 4월 16일
can u please tell me how can i read each row into x,y,z values and then use them in the above mentioned code. after calculating this euclidean distance i need to find the angle between the distances connecting these 60 points?
dpb
2015년 4월 16일
Just use the indices of the arrays...if the data are in X, then X(i,:) is point i, so X(i,1), X(i,2), X(i,3) --> [xi,yx,zi], respectively.
krishnasri
2015년 4월 16일
how can the same be done using pdist for a 60x3 values from two sheets? i.e., two excel sheets having 60x3 values, i need to calculate euclidean distance between values of two sheets
dpb
2015년 4월 17일
Depends on what you want as compare whom to whom...basically, read the two sheets into different arrays and then confound them together in the desired arrangement that satisfies pdist for the desired comparison. What isn't clear is whether you've got a position-by-position between the two or the "all possible comparisons" case.
krishnasri
2015년 4월 17일
Actually I have 60x3 values in two different excel sheets, I need to calculate the euclidean distance between these two sheets. I want euclidean distance between A1.xlsx and A2.xlsx sheets
krishnasri
2015년 4월 18일
sheet0= xlsread('N.xlsx');
sheet1= xlsread('A.xlsx');
D = pdist2(sheet0,sheet1,'euclidean');
is the code which i tried, which is giving an error,
??? Attempt to execute SCRIPT pdist2 as a function:
D:\pdist2.m
can u please help sort it out..
dpb
2015년 4월 18일
Looks like you've got a script pdist2 that's aliasing the TMW-supplied one. What does
which pdist2
show?
krishnasri
2015년 4월 19일
I didn't understand what you meant by which pdist2? I've matlab r2010a installed.
dpb
2015년 4월 19일
편집: dpb
2015년 4월 21일
Type it in at the command line...see
doc which
It'll show you which is the referenced pdist2 actually being called and in your above error the string "D:\pdist2.m" certainly makes it appear as if the problem is there is a script called PDIST2 which, if really so, is aliasing the TMW-supplied PDIST2 that you're trying to use.
The likely thing is that you named your top-level script pdist2 without realizing there is a builtin function of that name; if so rename that script to something else. Since Matlab is case-sensitive, use "PDIST2.m" or "pDist2.m" or some other name entirely, but anything but "pdist2.m".
PS:
"anything" above of course means "anything except pdis2.m or any other builtin function*.
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Gaussian Process Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)