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

1 visualización (últimos 30 días)
Craig Stevens
Craig Stevens el 7 de Jul. de 2020
Editada: madhan ravi el 7 de Jul. de 2020
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

Respuestas (1)

madhan ravi
madhan ravi el 7 de Jul. de 2020
Editada: madhan ravi el 7 de Jul. de 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'

Categorías

Más información sobre Tables en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by