Compute standard deviations for each element across several matrices

조회 수: 17 (최근 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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by