find distance between 2 points

I need to find the distance between 2 points. what is wrong with the script?
function d = finddist(A,B)
s = B-A
d = findmod(s)
this is what is coming when i am running it. Error using finddistance (line 2) Not enough input arguments. please help me out with the corrections to be done.

2 个评论

The error message contains "finddistance", but you post the code of "finddist". Which is "line 2"?
thankyou for the help, appreciated it.

请先登录,再进行评论。

 采纳的回答

Star Strider
Star Strider 2014-11-15

1 个投票

Not to rain on your parade, but I would just use the hypot function.

7 个评论

how to use the hypot function while calculating the distance? can you please explain?
The help documentation explains it. Was there a particular sentence in there that was confusing?
The hypot function returns the square root of the sum of squares of its two arguments. So considering them each to be sides of a right triangle, hypot computes the hypotenuse.
For example:
p1 = [3,4]; % First Point [x,y]
p2 = [7,8]; % Second Point [x,y]
dp = p1-p2; % Difference [x,y]
d = hypot(dp(1),dp(2)); % Distance Between ‘p1’ And ‘p2’
thanks, but in the help commands i could not understand the part where myhypot is being used eg.
myhypot = @(a,b)sqrt(abs(a).^2+abs(b).^2);
My pleasure.
That demonstrates a way of doing essentially the same thing hypot does with Anonymous Functions. (The built-in hypot function is more robust.)
The anonymous function you quoted takes the absolute value of the arguments (allowing for complex arguments), sums the squares of them, and then takes the square root. It is there for illustration purposes only and has nothing at all to do with the way you would use the built-in hypot function.
thank you for all the help

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by