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!

 Réponse acceptée

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 commentaires

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 le 8 Juin 2015
Modifié(e) : Star Strider le 8 Juin 2015
My pleasure!
If my Answer solved your problem, please Accept it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by