generate mean, variance and std using built in function

10 ビュー (過去 30 日間)
Me
Me 2022 年 8 月 25 日
編集済み: dpb 2022 年 8 月 26 日
Hi
I am wondering how to generate mean, variance and std using built in function for the above numbers using built in function.
doing it with loops causing many bugs.
A=my array;
sum1=0;
for i=1:length(A)
sum1=sum1+A(i);
end
M=sum1/length(A);
sum2=0;
for i=1:length(A)
sum2=sum2+ (A(i)-M)^2;
end
V=sum2/length

回答 (2 件)

Torsten
Torsten 2022 年 8 月 25 日
help mean
help var
help std
  1 件のコメント
Cris LaPierre
Cris LaPierre 2022 年 8 月 26 日
Learn how to use these and other functions in Ch 7 of MATLAB Onramp.

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


dpb
dpb 2022 年 8 月 25 日
編集済み: dpb 2022 年 8 月 26 日
stats=[[mean(A,2);var(A,2);std(A,2)];
[mean(A,1);var(A,1);std(A,1)];]
will give you and array of the statistics by class followed by a row by year across classes -- whiich may or may not be of real interest.
I'd recommend converting to a table, though, and then you can use groupsummary (or grpstats if you have the Statistics TB) and have labels and everything automagically...

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by