Splitapply command and merge results
2 views (last 30 days)
In general I am using this command "splitapply" in order to find mean (average) of a group of data.
[N, edges, bin] = histcounts(B, edges);
mean_B=splitapply(@mean, B, bin) %mean
%B is 100x1 double
But I would like to make a code that will :
1) Group my data into bins from edges : 1:0.5:10 (min=1, max=10 with step equal to 0.5)
2) Compute the means of the values in each bin (lets call it set1).
3) Group my data into bins from edges : 2:1:10 (min=2, max=10 with step equal to 1)
4) Compute the means of the values in each bin (set2).
5) Merge two sets of data
Could you please help me in order to make it?
Thanking you in advance
Rik on 26 Jul 2021
The question for you is what you mean by merging, but steps 1 to 4 are below.
%generate example data
edges1=[1 0.5 10];
edges2=[2 1 10];
B(B<msm(1) | B>msm(3))=;%remove data outside of bounds
[~, ~, bin] = histcounts(B, edges);
mean_B=splitapply(@mean, B, bin);
mean_B((end+1):(numel(edges)-1))=NaN;%extend to fill all bins