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

1 view (last 30 days)
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

Accepted Answer

Cedric
Cedric on 31 Oct 2013
Edited: Cedric on 31 Oct 2013
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.
  3 Comments
Cedric
Cedric on 31 Oct 2013
Edited: Cedric on 31 Oct 2013
You're welcome. The whole approach should be something like
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) ;
And then, if the purpose is to plot only non-zero bin statistics..
lat_bin = -90:0.5:90 ;
id_nz = mean_bin ~= 0 ;
figure(1) ; clf ; hold on ;
plot( lat_bin(id_nz), mean_bin(id_nz) ) ;
errorbar( lat_bin(id_nz), mean_bin(id_nz), ...
-std_bin(id_nz), std_bin(id_nz) ) ;
Note that you might have enough data points in each bin not to have to eliminate "empty bins" from display.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!