MATLAB: Finding mean of data between rows data based on information in column data

columndata organisationlatitudemeanrowstandard deviation

I have a matrix in which the rows represent a sample and the columns represent the data for each of the samples. One of the columns (6) contains a large amount of latitudes. Some of these latitude overlap and some are very similar. As there is an uneven spread of latitudes I wish to get the mean and standard deviation of the mean for the data in column 13 for the different samples that fall between half a degree in latitude (ie so that the data of any samples latitude that falls between -60 and -60.499 is put together to derive a mean and standard deviation from this). How would I go about doing this? Thank you, Natalie

Best Answer

Doesn't my answer to your previous question about binning answer this question as well?
If you didn't want to bin the data set like in your previous question, but compute some statistics for entries whose latitude fall in a given range, e.g. ]-60.5,-60], you could do it as follows:
id = data(:,6) > -60.5 & data(:,6) <= -60 ;
selection = data(id,13) ;
theMean = mean(selection) ;
theStd = std(selection) ;
etc ..
If you wanted to bin by latitude, i.e. obtain a statistics on bands, you could proceed the same way we did in your previous question, but this time on a "1D array". Assuming that you data lies in the range of latitudes [-89.5, 89.5]
lat_binID = 181 + ceil( data(:,6) ./ 0.5 ) ;
mean_bin = accumarray( lat_binID, data(:,13), [361, 1], @mean ) ;
std_bin = accumarray( lat_binID, data(:,13), [361, 1], @std) ;
Note that I didn't test this code, so you would have to check that it is working.