function env = envelope(A) % Calculate the envelope of a matrix A % Assume that A is symmetric. [m,n] = size(A); env = 0; for k = 2:n v = A(k,1:k-1); t = min(find(v)); if (t > 0) env = env + (k-t); end end