MATLAB: How to extract the diagonal of a given matrix

doit4meextractdiagusingsize

How can I extract the diagonal of a given matrix with using size? I know we can do it directly with diag.

Best Answer

A(sub2ind(size(A),1:size(A,1),1:size(A,2)))