From: Matt Fig on
"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
"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
"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
"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)
First  |  Prev  | 
Pages: 1 2
Prev: Workaround?
Next: AIC & BIC in GMM