m_mag2geo & m_geo2mag complain of "Attempt to reference field of non-structure array"

3 views (last 30 days)
Hi, This problem persists regardless of the arguments i enter (i.e. which lat and long). The function calls the private m_map function
mc_coords
which hits the error on line 74:
lambda=MAP_PROJECTION.coordsystem.lambda;
Anyone else experience this? Any ideas?
Cheers,
Neil

Accepted Answer

Geoff Hayes
Geoff Hayes on 15 Nov 2014
Neil - this error message is telling you that the code is treating a variable as if it were a structure with fields when in fact (for whatever reason) it isn't. For example, the following code generates the same error
x = [];
x.test;
Attempt to reference field of non-structure array.
The function in question, mc_coords is assuming that MAP_PROJECTION is a structure with a field named coordsystem. If you look at the code from mc_coords.m, this variable is global
global MAP_PROJECTION MAP_COORDS
If this variable has not been initialized elsewhere then it will be empty (like x in the above example) and so will throw the error. What you need to do is run the m_proj function which will initialize the map projection global variable (and others as well). You will be required to choose the projection type and provide any supporting information.
For example, to use the orthographic projection, type
m_proj('set','Orthographic')
to see what attributes/parameters can be set for this projection. To choose this projection with default values use
m_proj('Orthographic')
To view all projections, type
m_proj('set')
  2 Comments
Neil
Neil on 16 Nov 2014
Thanks a lot for this answer Geoff. I'm happy to have overcome this problem, but I think the m_geo2mag functions could explicitly state that they require other input to work. I'm not sure why it's neccesary to specify a projection as, in using this function, one is not actually mapping anything but rather changing between two (spherical) bases. What difference could different projections make on the outcome? Magnetic declination shouldn't depend on such a choice.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!