Is the following sample mean and variance fully vectorised?

1 回表示 (過去 30 日間)
Adarsh Kumar
Adarsh Kumar 2019 年 5 月 18 日
コメント済み: Adarsh Kumar 2019 年 5 月 18 日
I wish to calculate the sample mean and the variance. The following is an attempt:
mu=sum(X)/m;
sigma2=sum((X-mu).^2)/m;
mu=mu.';
sigma2=sigma2.';
Is the above fully vectorised as I haven't used any loops (I'm new to this sort of vectorised implementation, so I'm not sure if this code above is fully vectorised or not)?
Any help is highly appreciated.

回答 (1 件)

madhan ravi
madhan ravi 2019 年 5 月 18 日
編集済み: madhan ravi 2019 年 5 月 18 日
MATLAB already has inbuilt functions named mean() and var() .
  3 件のコメント
madhan ravi
madhan ravi 2019 年 5 月 18 日
The best what you can is you can compare the speed with your code and Matlab’s inbuilt function using tic toc . Looks to me that your code is already vectorised.
Adarsh Kumar
Adarsh Kumar 2019 年 5 月 18 日
Thanks Madhan.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by