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 comentarios

Jan
Jan el 16 de Nov. de 2014
The error message contains "finddistance", but you post the code of "finddist". Which is "line 2"?
RITTIK KUMAR GHOSH
RITTIK KUMAR GHOSH el 29 de Dic. de 2014
thankyou for the help, appreciated it.

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 15 de Nov. de 2014

1 voto

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

7 comentarios

RITTIK KUMAR GHOSH
RITTIK KUMAR GHOSH el 15 de Nov. de 2014
how to use the hypot function while calculating the distance? can you please explain?
Image Analyst
Image Analyst el 15 de Nov. de 2014
The help documentation explains it. Was there a particular sentence in there that was confusing?
Star Strider
Star Strider el 15 de Nov. de 2014
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 el 16 de Nov. de 2014
Editada: Star Strider el 16 de Nov. de 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 el 16 de Nov. de 2014
Editada: Star Strider el 16 de Nov. de 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.
RITTIK KUMAR GHOSH
RITTIK KUMAR GHOSH el 29 de Dic. de 2014
thank you for all the help
Star Strider
Star Strider el 29 de Dic. de 2014
My pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 15 de Nov. de 2014

Comentada:

el 29 de Dic. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by