Performing a function (such as standard deviation) on groups of data

3 views (last 30 days)
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

Answers (1)

madhan ravi
madhan ravi on 7 Jul 2020
Edited: madhan ravi on 7 Jul 2020
[~, ~, 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'

Community Treasure Hunt

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

Start Hunting!