MATLAB: How to select particular rows from a large matrix

satellite dataselecting data from a matrix

I have been working with the satellite data. So I have exported some data into matlab which contains nearly 16,000 rows and 6 columns. The first 2 columns are latitude and longitude and next columns contain various data fields like CO2 etc. what should I do to select the data that lies between particular latitude and longitudes. like limits of latitude are 20 to 30 and limits of longitude are 40 to 50.

Best Answer

small example: x=zeros(6,6); x(:)=1:numel(x)
x =
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
% now select the row(s) that have first column number between 3 and 5
x(x(:,1)>2 & x(:,1)<6 , :)
% if you want to add constraints on column 2 aswell:
x( x(:,1)>2 & x(:,1)<6 & x(:,2)>8 & x(:,2)<11 , :)