I have two datasets that represent longitude in different ways. The first represents longitude as degrees from east to 180, but then as negative east so that I have a series which looks like:

[0:180, -180:0];

I then have another dataset that represents longitude as degrees east but with a range of 0 to 360, i.e.:


In order to convert these to the same format, can I simply use this?

lon2(lon2 > 180) = lon2(lon2 > 180)-360;

Note my example here is written in MATLAB. This basically shows that I can change the second longitude coordinates by simply subtracting 360 from those longitude values that are greater than 180. Does this make sense?


3 Answers 3


The database with the negative longitude angles is storing longitude as eastings and westings, whereas the other database is storing everything as eastings.

It appears you prefer your data as eastings and westings. Your methodology for changing eastings greater than 180 degrees to westings is correct: where the longitude angle is greater than 180 subtract 360 from it (i.e. longitude angle - 360).


In Matlab if you have the mapping toolbox you can simply do:


And your approach is totally right, but if you have to do it more often or with other dataset with diferent conventions you can set up functions analogous to those in the maping toolbox. Such as:

function lon = wrapTo180(lon)
     q = (lon < -180) | (180 < lon);
     lon(q) = wrapTo360(lon(q) + 180) - 180;


function lon = wrapTo360(lon)
    positiveInput = (lon > 0);
    lon = mod(lon, 360);
    lon((lon == 0) & positiveInput) = 360;
  • 1
    $\begingroup$ This requires the Mapping Toolbox. If the OP's institution has not paid for this, it might be worth creating a similar function using the (correct) formulation in the question. $\endgroup$ Commented Jan 5, 2018 at 10:16
  • 1
    $\begingroup$ You are right, I've edited the answer accordingly. $\endgroup$ Commented Jan 5, 2018 at 16:32

If you wish to convert west-east longitude to eastward longitude, you can use the loop below, where lon represents your matrix with west-east longitude:

N = length (lon)

long = abs (lon);


while i<N+1;

  eastward_long(i) = (long(i) - floor(long(i) / 360) * 360) * (lon(i) / long(i)) - 180 * ((lon(i) / long(i)) - 1); 

  i = i + 1;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.