필터 지우기
필터 지우기

calculate the distance between two successive dots

조회 수: 1 (최근 30일)
bil bbil
bil bbil 2014년 3월 25일
편집: bil bbil 2014년 3월 25일
Hello friends..
  • my table contains 79 points
*here is my code
=======================
  • T = zeros;
*x=0;z=0;
  • a=length(points);%79points
*for i = 1:a
*for j = i+1:a
  • x = x + 1;
  • d1 = norm(points(j)-points(i));
  • T(x,:) = d1;
end
end
end
xlswrite('d:\result.xlsx',T);
========================================
*I want to calculate the distance between two successive dots ie: (point1,point2),(point3,point4),point5,point6)
*I normally get 39 distance but I got 3081 distance(because the loop it calculated the distance between all points)

채택된 답변

Joseph Cheng
Joseph Cheng 2014년 3월 25일
you'll have to do something like this
T = zeros;
x=0;z=0;
a=length(points);%79points
for i = 1:2:a
x = x + 1;
d1 = norm(points(i+1)-points(i));
T(x,:) = d1;
end
xlswrite('d:\result.xlsx',T);
Since you want just points 1 and 2 , then 3 and 4, etc. we can use the i=1:2:a to increment i by 2, and compare i to i+1. This way i will be 1, 3, 5 and the compared point will be 1+1, 3+1 , 5+1 (or 2,4,6).
  댓글 수: 1
bil bbil
bil bbil 2014년 3월 25일
편집: bil bbil 2014년 3월 25일
thank you very much...

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by