How can I calculate the mean of a vector ?

3 ビュー (過去 30 日間)
Mallouli Marwa
Mallouli Marwa 2018 年 7 月 12 日
コメント済み: Guillaume 2018 年 7 月 12 日
Hi
How can I calculate the mean of a vector ?
V_freq1 = 2*abs(VOLT1(6:NFFT/64))./( 2*abs( DISP1 (6:NFFT/64) ).*(2*pi*10)^2);
VOLT1, disp1 are vectors.
Please help me Best,
  3 件のコメント
Mallouli Marwa
Mallouli Marwa 2018 年 7 月 12 日
Mean (V_freq1)
An error is appeared
Torsten
Torsten 2018 年 7 月 12 日
mean, not Mean

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

採用された回答

KSSV
KSSV 2018 年 7 月 12 日
mean(V_freq1)
If your data has NaN's..have a look on nanmean.
% mean with inbuilt command
a = rand(100,1) ;
themean = 0 ; % the mean
for i = 1:length(a)
themean = themean+a(i) ;
end
themean = themean/length(a) ;
  3 件のコメント
Steven Lord
Steven Lord 2018 年 7 月 12 日
The 'omitnan' option for mean was introduced in release R2015a.
Guillaume
Guillaume 2018 年 7 月 12 日
Steven, it's a long standing request of mine that this be documented in the function doc (just under the Introduced in ...). It would greatly help in writing backward compatible code.

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

その他の回答 (1 件)

Jan
Jan 2018 年 7 月 12 日
編集済み: Jan 2018 年 7 月 12 日
Or:
m = sum(V_freq1) / numel(V_freq1)
Good ideas to solve such problems:
docsearch mean
help mean
Internet search engine: "Matlab mean"
For old Matlab versions and ignoring NaNs:
index = ~isnan(v);
m = sum(v(index)) / sum(index)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by