0

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
    It might help us if you could show us a sample of your data file (perhaps the first few rows and columns?) as well as the expected output that you want (how do you want the data stored?). – Adriano Jun 29 '14 at 07:09
  • Please look at the edited question @Adriano – Astrolink Jun 29 '14 at 07:32
  • Do you mean to say the data file contains latitude of stroke in first column, and longitude of stroke in second column? Is the data stored in a .csv file? Have you been able to read the data into a Matlab array? – littleO Jun 29 '14 at 07:36
  • Data is .loc file. I have imported into MATLAB as matrix but don't know how to do this sorting. – Astrolink Jun 29 '14 at 07:37

1 Answers1

1

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
Adriano
  • 41,576