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

3 Ansichten (letzte 30 Tage)
Shayma Al Ali
Shayma Al Ali am 12 Mär. 2021
Beantwortet: Matt J am 12 Mär. 2021
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.

Antworten (1)

Matt J
Matt J am 12 Mär. 2021
numBins=10;
bins=discretize(new_u10wcav,numBins);
meany=splitapply(@mean,wc_average(:),findgroups(bins(:)));

Kategorien

Mehr zu Weather and Atmospheric Science finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by