distance function sometimes giving atan2 error, why is this?
13 views (last 30 days)
Show older comments
Using matlab2013 I am very confused by this error. For the same input's it'll sometimes give me an error and sometimes not. example: I have two vectors, lets call them A and B.
This gives me an error:
distance(A(96562),B(96562),A,B,'radians');
Error using atan2
Inputs must be real.
Error in distance>greatcircledist (line 160)
rng = r * 2 * atan2(sqrt(a),sqrt(1 - a));
Error in distance (line 101)
rng = greatcircledist(lat1, lon1, lat2, lon2, ellipsoid(1));
The values are such:
A(96562)
ans =
-0.360233642765199
B(96562)
ans =
2.132182023972182
Here's the odd thing, plugging in the numbers does not give me an error.
distance(-0.360233642765199,2.132182023972182
,A,B,'radians');
This works fine!
The following does not
distance(A(96562),2.132182023972182
,A,B,'radians');
but now the following does?
distance(-0.360233642765199,B(96562)
,A,B,'radians');
can someone help me understand what is happening or how to figure this out? thanks!
6 Comments
Roger Stafford
on 21 Jun 2016
It should be pointed out that this current question was asked by Pedro four days ago while the question you answered and which was accepted, Steven, was asked only nine hours ago. By that time the question had become more precise and he had narrowed things down to a single set of four numbers given in their IEEE hex form. It is a natural way to proceed and in my opinon does not involve unnecessary repetition of questioning.
Steven Lord
on 22 Jun 2016
Fair enough. My comment was intended more as an FYI that the cause of this problem has been identified elsewhere and so we don't need to continue investigating here.
Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!