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

Jan
Jan 2014년 11월 16일
The error message contains "finddistance", but you post the code of "finddist". Which is "line 2"?
RITTIK KUMAR GHOSH
RITTIK KUMAR GHOSH 2014년 12월 29일
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

RITTIK KUMAR GHOSH
RITTIK KUMAR GHOSH 2014년 11월 15일
how to use the hypot function while calculating the distance? can you please explain?
Image Analyst
Image Analyst 2014년 11월 15일
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 2014년 11월 16일
편집: Star Strider 2014년 11월 16일
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 2014년 11월 16일
편집: Star Strider 2014년 11월 16일
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 2014년 12월 29일
thank you for all the help
Star Strider
Star Strider 2014년 12월 29일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

질문:

2014년 11월 15일

댓글:

2014년 12월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by