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 commentaires

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

Connectez-vous pour commenter.

 Réponse acceptée

Star Strider
Star Strider le 15 Nov 2014

1 vote

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

7 commentaires

RITTIK KUMAR GHOSH
RITTIK KUMAR GHOSH le 15 Nov 2014
how to use the hypot function while calculating the distance? can you please explain?
Image Analyst
Image Analyst le 15 Nov 2014
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 le 16 Nov 2014
Modifié(e) : Star Strider le 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 le 16 Nov 2014
Modifié(e) : Star Strider le 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.
RITTIK KUMAR GHOSH
RITTIK KUMAR GHOSH le 29 Déc 2014
thank you for all the help
Star Strider
Star Strider le 29 Déc 2014
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by