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!

답변 (2개)

the cyclist
the cyclist 2015년 11월 30일
편집: the cyclist 2015년 11월 30일

1 개 추천

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

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

댓글을 달려면 로그인하십시오.

John D'Errico
John D'Errico 2015년 11월 30일
편집: John D'Errico 2015년 11월 30일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Environmental Engineering에 대해 자세히 알아보기

질문:

2015년 11월 30일

댓글:

2015년 12월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by