find length of a line use 2 dots

조회 수: 3 (최근 30일)
Rahma Yeni
Rahma Yeni 2012년 3월 23일
Hello.. I have code like this
x = [0.2177, 0.6302, 0.9597, 0.6025];
y = [0.4284, 0.7822, 0.5073, 0.1564];
for m = 1:length(x)
for n = 1:length(x)
(n)= sqrt((x(:,n+m) - x(:,n)).^2 + (y(:,n+m) - y(:,n)).^2)
end
end
pjgtot = sum(pjg)
and the result are:
pjg =
0.5434
pjg =
0.5434 0.4291
pjg =
0.5434 0.4291 0.5007
??? Attempted to access x(:,5); index out of
bounds because size(x)=[1,4].
Error in ==> maze_solution at 322
pjg (n)= sqrt((x(:,n+m) - x(:,n)).^2 +
(y(:,n+m) - y(:,n)).^2)
>>
the result is true, that is :
pjg = 0.5434 0.4291 0.5007
but it give some error too.. why it happened .. is there something wrong with my code..?? manual calculations to obtain these results is (in this example, i use x = 0.2177, 0.6302, and y = 0.4284, 0.7822)
pjg = sqrt((0.6302-0.2177)^2 + (0.7822-0.4284)^2)
where is the fault..??
thank you.. :)

채택된 답변

Jonathan Sullivan
Jonathan Sullivan 2012년 3월 23일
dist = sum(sqrt(diff(x).^2+diff(y).^2))

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by