Calculating the Standard Deviation

Hi,
How to read each value from a txt file for calculation of standar deviation (SD).
For example, I have my txt file with Y values (frequencies) and I want to caulate how much of variation from the mean the frequencies change. I can do it manually but for many data this would be too slow process. So, I want to automatically read and calculate the SD.
My file has jus one colum. To calculate the SD I have to calculate mean first, so would be: Mean = A/n
The variable A would be the sum of each value in my file divivded by the total number of values. Attached is the file. Then, I can calculate the SD which is
the sqr((A(1)-Mean)^2 + (A(2)-Mean)^2 + ... + (A(N)-Mean)^2/n-1).
Is there a way to do it automatic?
Thank you

 採用された回答

Star Strider
Star Strider 2021 年 5 月 5 日

0 投票

Two options are to either calculate it directly, or use the normalize funciton —
y = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/608245/y%20axis.txt')
y = 400×1
10.5400 10.5200 10.5231 10.5138 10.5015 10.5015 10.5108 10.5046 10.5231 10.4846
ymean = mean(y)
ymean = 10.2223
stdvct = sqrt((y-ymean).^2)
stdvct = 400×1
0.3177 0.2977 0.3008 0.2916 0.2792 0.2792 0.2885 0.2823 0.3008 0.2623
[N,C,S] = normalize(y,'center','mean')
N = 400×1
0.3177 0.2977 0.3008 0.2916 0.2792 0.2792 0.2885 0.2823 0.3008 0.2623
C = 10.2223
S = 1

5 件のコメント

Tay
Tay 2021 年 5 月 5 日
Thanks, Star.
Don't know why I have this error
Error using normalize
Too many output arguments.
Error in Untitled (line 2)
[N,C,S] = normalize(y,'center','mean');
Tay
Tay 2021 年 5 月 5 日
y = readmatrix('y axis.txt');
[N,C,S] = normalize(y,'center','mean');
Star Strider
Star Strider 2021 年 5 月 5 日
My pleasure!
Don't know why I have this error
Nor do I.
I am using R2021a, as does the online application that I used to run this. If you are not, perhaps an upgrade is in order?
Tay
Tay 2021 年 5 月 19 日
Thank you.
I calculated directed using the equation more easy than tryng to find the error xD
Star Strider
Star Strider 2021 年 5 月 19 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

Tay
2021 年 5 月 5 日

コメント済み:

2021 年 11 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by