Problem with enu2geodetic() Function
Show older comments
DISCLAIMER: I work in a secure environment, so I am unable to share any code. I will try my best to explain the issue as specifically as possible.
ISSUE: When I run enu2geodetic() using the proper arguments and the 'wgs84Ellipsoid' object, I get the following error:
*******************************************************************************************************************************************************************
Index exceeds the number of array elements. Index must not exceed 1.
Error in ecef2geodetic (line 74)
e2 = ellipsoid(2) ^ 2; % Square of first eccentricity
Error in enu2geodetic (line 35)
[lat, lon, h] = ecef2geodetic(spheroid, x, y, z);
Error in [REDACTED] (line [REDACTED])
[lat(i), lon(i), alt(i)] = enu2geodetic(x(i), y(i), z(i), latCenter, lonCenter, altCenter, wgs84Ellipsoid);
*******************************************************************************************************************************************************************
The problem is that inside ecef2geodetic(), the 'ellipsoid' variable is just a single value (1-element array), so it errors when ellipsoid(2) is referenced.
My code worked perfectly fine as of yesterday. I did not make any changes to the code or my environment prior to today where I am now getting the error. It makes me wonder if MathWorks changed something internally.
Any and all insight is greatly appreciated.
4 Comments
Image Analyst
on 4 Aug 2023
The only thing I can think of is that one or more of
- spheroid, x, y, or z or
- x(i), y(i), z(i), latCenter, lonCenter, altCenter, wgs84Ellipsoid
must have changed from the time you ran it yesterday.
Alex Lipp
on 7 Aug 2023
Alex Lipp
on 7 Aug 2023
I see that wgs84Ellipsoid is a built-in function in the Mapping toolbox. Make sure that you are not ghosting this function by creating a variable with the same name (it can be that MATLAB is interpreting the reference as a variable, rather than a function due to some syntax usage). Try E = wgs84Ellipsoid and see what you get for E. If it's not a referenceEllipsoid object, then that is the problem.
Answers (0)
Categories
Find more on Geographic Coordinate Reference Systems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!