<p>In Matlab if you have the mapping toolbox you can simply do:</p>
<pre><code>lon2=wrapTo180(lon2);
</code></pre>
<p>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:</p>
<pre><code>function lon = wrapTo180(lon)
     q = (lon &lt; -180) | (180 &lt; lon);
     lon(q) = wrapTo360(lon(q) + 180) - 180;
</code></pre>
<p>And</p>
<pre><code>function lon = wrapTo360(lon)
    positiveInput = (lon &gt; 0);
    lon = mod(lon, 360);
    lon((lon == 0) &amp; positiveInput) = 360;
</code></pre>

CC BY-SA 3.0
2018-01-05T10:16:52.570Z
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.
Semidiurnal Simon
CC BY-SA 3.0
2018-01-05T16:32:48.770Z
You are right, I've edited  the answer accordingly.
Camilo Rada
CC BY-SA 4.0
2018-01-04T21:32:07.790Z
2022-04-11T22:46:13.393Z
2022-04-11T22:46:13.393Z
Camilo Rada
<p>If you wish to convert <em>west-east longitude</em> to <strong>eastward longitude</strong>, you can use the loop below, where lon represents your matrix with <em>west-east longitude</em>:</p>
<pre><code>N = length (lon)

long = abs (lon);

i=1;

while i&lt;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;

end
</code></pre>

CC BY-SA 4.0
2022-04-11T08:25:53.183Z
2022-04-11T09:48:36.440Z
2022-04-11T09:48:36.440Z
FVMachado
<p>The database with the negative longitude angles is storing longitude as eastings and westings, whereas the other database is storing everything as eastings.</p>

<p>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).</p>

CC BY-SA 3.0
2015-10-05T09:21:26.423Z
2015-10-05T09:21:26.423Z
Fred
<p>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:</p>

<pre><code>[0:180, -180:0];
</code></pre>

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

<pre><code>0:360;
</code></pre>

<p>In order to convert these to the same format, can I simply use this?</p>

<pre><code>lon2(lon2 &gt; 180) = lon2(lon2 &gt; 180)-360;
</code></pre>

<p>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? </p>

<homework><matlab><geometry>
How do I convert between different east longitude coordinates?
Emma Tebbs
# How do I convert between different east longitude coordinates?

(Asked by: username_0 on 2015-10-05)

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.:

```
0:360;

```

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?

**Tags:** homework, matlab, geometry


---

## 3 answers

### Answer by username_4 on 2015-10-05. Score: 9 | Accepted answer

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).


---

### Answer by username_1 on 2018-01-04. Score: 3

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

```
lon2=wrapTo180(lon2);

```

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;

```

And

```
function lon = wrapTo360(lon)
    positiveInput = (lon > 0);
    lon = mod(lon, 360);
    lon((lon == 0) & positiveInput) = 360;

```

> **Comments:**
> **username_2**: 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.  
> **username_1**: You are right, I've edited  the answer accordingly.  

---

### Answer by username_3 on 2022-04-11. Score: 0

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);

i=1;

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;

end

```


---

