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!

 Akzeptierte Antwort

Star Strider
Star Strider am 8 Jun. 2015

0 Stimmen

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 Kommentare

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.
THANKS! :D
Star Strider
Star Strider am 8 Jun. 2015
Bearbeitet: Star Strider am 8 Jun. 2015
My pleasure!
If my Answer solved your problem, please Accept it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by