Compute standard deviations for each element across several matrices

19 ビュー (過去 30 日間)
Kim Arnold
Kim Arnold 2020 年 10 月 22 日
コメント済み: Ameer Hamza 2020 年 10 月 22 日
Hi everyone.
I have a cell array A.M_org{1, 1} ; A.M_org{1,2} etc. with 5 cells in total.
In each of the 5 cells I have another 3 cells such as A.M_org{1, 1} {1,i} where i is 1:3. Each cell contains a matrix of equal size namely 18x922.
I wanted then to calculate the mean for each element across the 3 matrices which works with:
A.M_avg = cellfun(@(x) {mean(cat(3, x{:}), 3)},A.M_org);
I wanted then calculate the standard deviation as well for each element across all the three Matrices such as for example for element 1 across the three matrices M1(1,1), M2(1,1), M2(1,1) using :
A.M_std = cellfun(@(x) {std(cat(3, x{:}), 3)},A.M_org);
this gave me an error saying :
Error using var (line 197)
W must be a vector of nonnegative weights, or a scalar 0 or 1.
Error in std (line 59)
y = sqrt(var(varargin{:}));
Error in @(x){std(cat(3,x{:}),3)}
does somebody know why the mean can be calculated this way for each element but the standard deviation can't?
Does anybody know how to compute the standard deviation of the elements across several matrices with equal size?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 22 日
2nd input to std() is a weight vector. Change it to this
std(cat(3, x{:}), [], 3)
  2 件のコメント
Kim Arnold
Kim Arnold 2020 年 10 月 22 日
Thanks! that works perfectly!
Ameer Hamza
Ameer Hamza 2020 年 10 月 22 日
I am glad to be of help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by