distance function sometimes giving atan2 error, why is this?
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
Walter Roberson
on 17 Jun 2016
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 ?
Pedro Ribeiro
on 21 Jun 2016
Edited: Walter Roberson
on 21 Jun 2016
Walter Roberson
on 21 Jun 2016
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.
Steven Lord
on 21 Jun 2016
FYI Pedro asked this question again here, and my answer was accepted for that instance of this question.
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)
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!