How to average data within bins when values are not integers?

4 次查看(过去 30 天)
I'm analyzing whitecaps, named 'wc_average', against wind speed ('new_u10wcav'). I want to bin the windspeeds and average the whitecaps within those bins. I've tried to use accumuarray but I keep getting errors since my data aren't positive integers. The current code I've been trying comes up with the error
Error using splitapply (line 101)
The data variables must have the same number of columns as the vector of group numbers. The group number vector has 11 column(s), and data variable 1 has 1 column(s).
How do I fix it? My current code:
numBins=10;
[N,edges]=histcounts(new_u10wcav,numBins);
meany=splitapply(@mean,wc_average,findgroups(edges));
The data should be founds in testfiles.mat that I attached.

回答(1 个)

Matt J
Matt J 2021-3-12
numBins=10;
bins=discretize(new_u10wcav,numBins);
meany=splitapply(@mean,wc_average(:),findgroups(bins(:)));

类别

Help CenterFile Exchange 中查找有关 Weather and Atmospheric Science 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by