Finding mean of data between rows data based on information in column data
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Cedric
2013-10-31
编辑:Cedric
2013-10-31
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 个评论
Cedric
2013-10-31
编辑:Cedric
2013-10-31
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!