How to compute the standard deviation of each column in a matrix?
21 ビュー (過去 30 日間)
古いコメントを表示
I have some code that creates a matrix of data points and then computes the average value for each column and plots these average values. However, I want to add some error bars to my graph where each error bar represents the standard deviation across each column entry in the original matrix. Is there a concise way to compute the standard deviation for each column so that I can store it and use these standard deviations to make a plot (using something like 'errorbar(x, y, err)'? Thanks!
0 件のコメント
回答 (2 件)
the cyclist
2021 年 8 月 27 日
編集済み: the cyclist
2021 年 8 月 27 日
If A is your array, then
s = std(A)
is a row vector, where each element is the standard deviation of the corresponding column. See the documenation for std for details.
Also, be sure to be clear about whether your error bars represent the standard deviation or the standard error of the mean.
2 件のコメント
the cyclist
2021 年 8 月 29 日
You could use the isnan function to keep track of how many elements are NaN. So, calculate the standard deviation, and divide by the square root of the number of elements that are not NaN.
Steven Lord
2021 年 8 月 28 日
To be certain that you're taking the std over each column, specify the dim input argument as described on the documentation page for the std function.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Errorbars についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!