MATLAB: Standar deviation of a matrix (specific elements)

deviationoff-diagonal elementsstandar

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

Best Answer

  • 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(:))));