Info
此问题已关闭。 请重新打开它进行编辑或回答。
How to perform repeated calculations on a different bin
1 次查看(过去 30 天)
显示 更早的评论
I have split my data into bins (5 million year spacing through time) and then performed calculations to remove NaNs, calculate the mean and calculate the standard deviation of the first bin (0-5million years).
I was just wandering if there is an easy way of repeating all of these calculations for the remaining bins (5-10myr, 10-15myr....etc)?
Thanks Charlie
回答(2 个)
Steven Lord
2016-10-25
Use discretize to bin your data then use the output from discretize as the subs input to accumarray.
% Sample data
n = 10;
x = n*rand(100, 1);
y = (1:100).';
% Bin it and accumulate the data in each bin
bin = discretize(x, 0:n);
A1 = accumarray(bin, y, [n 1], @mean);
% Accumulate the data in the bins using a FOR loop
A2 = zeros(n, 1);
for k = 1:n
A2(k) = mean(y(bin == k));
end
% These two results should be the same
[A1, A2, A1-A2]
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!