function result = computeMutualCoherence(A)
% Computes mutual coherence
%
% USAGE:
%
%    result = computeMutualCoherence(A)
%
% INPUT:
%    A:         input matrix
%
% OUTPUT:
%    result:    mutual coherence
%
% ..
%     [M N] = size(A);
%     if (N<2)
%         disp('error - input contains only one column');
%         u=NaN;   beep;    return
%     end
%
%     % normalize the columns
%     nn = sqrt(sum(A.*conj(A),1));
%     if ~all(nn)
%         disp('error - input contains a zero column');
%         u=NaN;   beep;    return
%     end
%     nA = bsxfun(@rdivide,A,nn);  % nA is a matrix with normalized columns
%     result = max(max(triu(abs((nA')*nA),1)));

    X = A/(diag(sqrt(diag(A'*A))));
    mcoh = abs(X'*X);
    V = diag(mcoh);
    V = -diag(V,0);
    mcoh = mcoh+V;
    result = max(max(mcoh));
end

opencobra
github-repos/MATLAB/opencobra-cobratoolbox/cobratoolbox-e60274d127f65d518535fd0814d20c53dc530f73/src/base/solvers/cardOpt/sparseLP/computeMutualCoherence.m
cobratoolbox
github-repos/MATLAB/opencobra-cobratoolbox
e60274d127f65d518535fd0814d20c53dc530f73