Prev: Workaround?
Next: AIC & BIC in GMM
From: Matt Fig on 8 Mar 2010 22:52 "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message > There's a special matlab function to do just that operation on a square matrix. Remarkably enough, it is called "trace". > > Roger Stafford D'oh. I am not sure I've ever even seen the TRACE function! I do note that it is an M-File which uses: t = sum(diag(a));
From: Jos (10584) on 9 Mar 2010 07:54 "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message Hi Roger, It's good to see you again, after such a long break! Did, by any chance, your email address change? Jos http://www.mathworks.com/matlabcentral/fileexchange/authors/10584
From: Jos (10584) on 9 Mar 2010 07:57 "Enosh Bale" <fergysonnaiyep(a)gmail.com> wrote in message <hn4a5i$j1p$1(a)fred.mathworks.com>... > that, given a square matrix, returns the sum of the diagonal elements. without using sum, diag(onal), or even TRACE : ones(1,min(size(A))) * A(eye(size(A))==1) Jos
From: Husam Aldahiyat on 9 Mar 2010 08:30
"Jos (10584) " <#10584(a)fileexchange.com> wrote in message <hn5giv$89f$1(a)fred.mathworks.com>... > "Enosh Bale" <fergysonnaiyep(a)gmail.com> wrote in message <hn4a5i$j1p$1(a)fred.mathworks.com>... > > that, given a square matrix, returns the sum of the diagonal elements. > > without using sum, diag(onal), or even TRACE : > > ones(1,min(size(A))) * A(eye(size(A))==1) > > Jos I like: >> sum(A(1:size(A)+1:numel(A))) Or without sum version: >> A(1:size(A)+1:numel(A))*ones(length(A),1) |