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!

 Respuesta aceptada

Star Strider
Star Strider el 8 de Jun. de 2015
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 comentarios

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.

Preguntada:

el 8 de Jun. de 2015

Editada:

el 8 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by