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 Commenti

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

Accedi per commentare.

 Risposta accettata

Star Strider
Star Strider il 15 Nov 2014

1 voto

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

7 Commenti

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’
RITTIK KUMAR GHOSH
RITTIK KUMAR GHOSH il 16 Nov 2014
Modificato: Star Strider il 16 Nov 2014
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);
Star Strider
Star Strider il 16 Nov 2014
Modificato: Star Strider il 16 Nov 2014
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
My pleasure!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by