matrix - locating the grids in which a dataset falls into and extracting this data in matlab -


i have 2 sets of data. 1 set of data matrix containing different samples in each row , information regarding each sample in columns, 1 of these columns contains longitude data , 1 contains latitude data sample. other dataset consists of 3 grids. 1 grid contains latitude of data, second grid contains longitude of data , third grid, data 1° latitude longitude grid.

what find out data in second dataset corresponds data in second dataset. mean this, if sample falls particular grid of second dataset, data in grid needs extracted , needs known sample data applies.

so in grid between latitudes 60 , 59, , longitudes 100 , 101 sample x falls. data in gridded dataset 10 particular grid. know 10 (the data in grid) applies sample x.

in end have grid data corresponds sample in new matrix act partner sample dataset (ie. if sample x in row 40 in matrix 10 in row 40), or alternatively added same dataset new column. keeping in mind samples fall same grid.

i'm inexperienced in matlab, have tried brushing tool not work example. think of potentially work round each long , lat in sample data number , find samples overlap in long , lat , intersect long in sample data long grid , same lat grid finding row , column each sample falls , find data each sample. seems long way go , i'm not sure how work well.

i have completed method , has worked extent.... have rows , columns in data each sample (ie. sample x can found in row 8 column 100). when try , extract data grid not matrix containing 1 column many columns, answer still in sample place of matrix. how go taking 1 data point each row of grid , ending matrix of 1 column (or 1 row in can turn column)?

thank you

presuming first data set in matrix x, first column latitude , second longitude , other columns existing data:

xlat = floor(x(1,:));  xlon = floor(x(2,:));  lat = % list of latitudes covered in grid lon = % list of longitudes covered in grid data = % matrix of data want extract - 2d grid 

such lat(n),lon(m) forms reference left-bottom corner of grid square, contains data in data(n,m). floor rounds down, between 100 , 101 linked 100, etc.

now:

   [~ n] = ismember(xlat,lat);    [~ m] = ismember(xlon, lon); 

n , m not latitudes or longitudes indexes relate points in data set x values in lat , lon refer value in grid data.

here's last trick - use sub2ind convert n , m references single reference position in grid, extract required data in 1 go:

ind = sub2ind(size(data),n,m); % presuming size of data lat x lon); xdata = data(ind); 

xdata should single column, same size number of rows in x.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -