dist = sum(sqrt(diff(x).^2+diff(y).^2))
find length of a line use 2 dots
7 次查看(过去 30 天)
显示 更早的评论
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.. :)
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!