Sorting and removing data in MATLAB

90 Views Asked by At

I am new to MATLAB and I have to analyze a file containing lighting data from WWLLN.

The data file contains:

latitude of stroke in first row, and longitude of stroke in second row

This file has lightning locations occurring globally.
However, I am only interested in lightning occurrences in the region bounded between 0 - 40°S latitudes and 135°E - 120°W(240°) longitudes.

For example this is a sample of the data I have:

-28.3377, -60.6544
-5.3784, 111.4730
-16.0437, -56.5725
-28.0908, 34.9937
14.7177, -108.6239
14.7636, -108.6201
14.6061, -108.7629
14.5823, -108.7795
14.6551,-108.6343

I should get:

-28.3377, -60.6544

The first column should only have values ranging from 0 to -40, and
The second column should have values ranging from 135 to 180 or -60 to -179.9999.

Can anyone help me with the MATLAB coding required to perform this.

1

There are 1 best solutions below

1
On

Use logical indexing on the matrix's rows:

M = [-28.3377  -60.6544;
      -5.3784  111.4730;
     -16.0437  -56.5725;
     -28.0908   34.9937;
      14.7177 -108.6239;
      14.7636 -108.6201;
      14.6061 -108.7629;
      14.5823 -108.7795;
      14.6551 -108.6343];

row_idx = (-40 <= M(:, 1) & M(:, 1) <= 0) ...
           & ((135 <= M(:, 2) & M(:, 2) <= 180) ...
               | (-180 < M(:, 2) & M(:, 2) <= -60));

filtered_M = M(row_idx, :)

This yields:

filtered_M =

  -28.3377  -60.6544