standar deviation of a matrix (specific elements)

Dear friends
I want to obtain the standar deviation of a square matrix but only off-diagonal elements. anyone could help me?
Thanks!

 采纳的回答

Two ways, both producing the same value:
M = rand(7); % Create Data
diagM = nan(1,size(M,1));
M = M + diag(diagM);
Mmean1 = mean(M(:),'omitnan');
Mmean2 = mean(M(~isnan(M(:))));

4 个评论

thanks star! but i dont understand. this program produce the standar deviation of a square matrix without diagonal elements? i need sd but only the elements off-the diagonal.
Long day. Wrote mean, meant std. This works:
M = rand(7); % Create Data
diagM = nan(1,size(M,1));
M = M + diag(diagM);
Mmean1 = std(M(:),'omitnan');
Mmean2 = std(M(~isnan(M(:))));
It sets the diagonal to NaN, then takes the mean of all elements that are not NaN.
My pleasure!
If my Answer solved your problem, please Accept it.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by