distance function sometimes giving atan2 error, why is this?

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 个评论

Hmmm.
Could you show
imag(A(96562))
?
Please also show the output of
num2hex(A(96562))
num2hex(B(96562))
that will give us a chance to test with the precise values you are using.
Could you confirm that you are using the distance() function from the Mapping Toolbox ?
sorry for the late response. Hope you are still here. I am using the distance function found here: /usr/local/apps/matlab-2013a/toolbox/map/map/distance.m
for all four values given in distance the value for imag is 0.
for all four values in order given to distance the hex value are: bff302fba03a0023, 4003ff6217b27e6b, 3ff302fba03a0023, bfe48a64f246bab5
passing those values into the distance formula gives me an error.
I just realized that I am going to need the complete A and B matrix. Perhaps you could attach a .mat file? You might need to zip it to fit the file space limits.
FYI Pedro asked this question again here, and my answer was accepted for that instance of this question.
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.
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.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by