Performing a function (such as standard deviation) on groups of data
1 次查看(过去 30 天)
显示 更早的评论
I have created runs that are based on if data is present. See below for the "raw data example". What i want to do is create a new matrix/table that is filled with analyzed data for each run. For example, I want to create a table filled with the standard deviation of each run, which would look similar to "Analyzed Example". Note that the std for run 1 was from lines 4 to 8. I am unsure if I explained this well enough and I would appreciate any assistance/guidance. Thank you.
Analyzed Example
Raw Data Example
0 个评论
回答(1 个)
madhan ravi
2020-7-7
编辑:madhan ravi
2020-7-7
[~, ~, c]= unique(Run, 'stable'); % Run is without zeros
STD = accumarray(c, (1:numel(Data)).', [], @std)
%or
STD = splitapply(@std, Data, findgroups(Run))
%or
STD = grpstats(array2table([Run,Data], 'VariableNames',{'Run', 'Data'} ),'Run','std')
%or
T = array2table([Run,Data], 'VariableNames',{'Run', 'Data'} );
STD = groupsummary(T, 'Run','std'
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!