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
2015 年 11 月 30 日
編集済み: the cyclist
2015 年 11 月 30 日
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
2015 年 12 月 1 日
the cyclist
2015 年 12 月 1 日
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
2015 年 11 月 30 日
編集済み: John D'Errico
2015 年 11 月 30 日
0 投票
カテゴリ
ヘルプ センター および File Exchange で Environmental Engineering についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!