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

 採用された回答

Star Strider
Star Strider 2015 年 6 月 8 日

0 投票

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 件のコメント

juan moreno
juan moreno 2015 年 6 月 8 日
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.
Star Strider
Star Strider 2015 年 6 月 8 日
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.
juan moreno
juan moreno 2015 年 6 月 8 日
THANKS! :D
Star Strider
Star Strider 2015 年 6 月 8 日
編集済み: Star Strider 2015 年 6 月 8 日
My pleasure!
If my Answer solved your problem, please Accept it.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Operating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by