standard deviation of same values in a matrix

Hello,
I couldn't find anything which could help me with my problem.
I have a matrix (n x 2) like shown below:
I want to calculate the standard deviation of column 2 for all records which have the same valaue in column 1. So I get this:
Is there a smart way to do this? Maybe is several steps?
Thanks!

Respuestas (2)

the cyclist
the cyclist el 30 de Nov. de 2015
Editada: the cyclist el 30 de Nov. de 2015
The accumarray function is designed for this:
M = [5 0.30;
5 0.35;
7 0.50;
7 0.51;
9 0.98;
9 0.87;
9 0.71];
[uniqueM,idxToUnique,idxFromUniqueBackToAll] = unique(M(:,1));
S = accumarray(idxFromUniqueBackToAll,M(:,2),[],@std)
stdDevM = [uniqueM,S]

2 comentarios

Fabi Boro
Fabi Boro el 1 de Dic. de 2015
Thank you! works quite well!
the cyclist
the cyclist el 1 de Dic. de 2015
The best form of thanks is accepting the solution, which rewards the person who helped you, and also points future users to good answers.

Iniciar sesión para comentar.

John D'Errico
John D'Errico el 30 de Nov. de 2015
Editada: John D'Errico el 30 de Nov. de 2015

0 votos

Download consolidator , from the file exchange. One line then.

Categorías

Preguntada:

el 30 de Nov. de 2015

Comentada:

el 1 de Dic. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by