how to calculate deviation for set of values??

1 回表示 (過去 30 日間)
M.Prasanna kumar
M.Prasanna kumar 2020 年 2 月 5 日
コメント済み: M.Prasanna kumar 2020 年 2 月 16 日
No of cases = 112; (112*9=1008)
in each case i have 9 obsevations( but there are missing values in between for which matlab treats them as Nan); so total i have an array of 1008*1
i calculted mean of 9 observations for each case. Now i want to calculate deviation of each observation( 9 observations) from the mean of that particular case.
M = strcat('iva','.xlsx' ); %% read excel file , iva file consists of 1008*1 array
M1 = xlsread(M);
mean_iva = zeros(112,1); %% initialising matrix
for ii = 1:9:1008
mean_iva(ii,1)= nanmean(M1(ii:ii+8)) %% calculating mean for each case
end
B = mean_iva(mean_iva~=0); %% MEAN for all 112 cases
dev = zeros(1008,1);

採用された回答

Guillaume
Guillaume 2020 年 2 月 5 日
You could do the same thing you've done for the mean, use a for loop.
However, a much simpler way is to reshape your input vector into 112 columns of 9 rows and simply call mean and std, no loop needed:
%M1: vector whose length is a multiple of 9
assert(mod(numel(M1), 9) == 0, 'Length of M1 must be a multiple of 9');
M1 = reshape(M1, 9, []); %reshape in rows of 9 elements
mean_iva = mean(M1, 1, 'omitnan'); %calculate the mean across the rows
std_iva = std(M1, 0, 1, 'omitnan'); %standard deviation (normalised by N-1) across the rows
  3 件のコメント
Guillaume
Guillaume 2020 年 2 月 7 日
You mean the want the difference from the mean? In this case, it's simply:
meandiff = M1 - mean_iva;
M.Prasanna kumar
M.Prasanna kumar 2020 年 2 月 16 日
thank you sir

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

その他の回答 (0 件)

カテゴリ

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