Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How to perform repeated calculations on a different bin

2 Ansichten (letzte 30 Tage)
Charlie Finnie
Charlie Finnie am 25 Okt. 2016
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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 Kommentare
Adam
Adam am 25 Okt. 2016
Depends how exactly you have split your data up, but assuming you put your code in a function then you can apply that function to any bin you choose or all bins in succession.
Chaya N
Chaya N am 25 Okt. 2016
How are you storing each of these bin data? (Arrays/ cells/ structures)

Antworten (2)

Steven Lord
Steven Lord am 25 Okt. 2016
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]

Chaya N
Chaya N am 25 Okt. 2016
Bearbeitet: Chaya N am 25 Okt. 2016
Put all the bin data into a cell array and use cellfun
all_bins_raw = {bin1,bin2,....,binN}; % put all raw data in one cell array
all_bins = cellfun(@(x) x(~isnan(x)),all_bins_raw,'UniformOutput',0); % Remove NaN's
bin_means = cellfun(@mean, all_bins);
bin_sds = cellfun(@std, all_bins);

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by