Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!b5g2000prd.googlegroups.com!not-for-mail
From: Nathan <ngreco32@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: given matrix, sum of diagonal elements
Date: Mon, 8 Mar 2010 18:03:48 -0800 (PST)
Organization: http://groups.google.com
Lines: 27
Message-ID: <ce0a552c-9379-4ad6-8549-b9c52a905529@b5g2000prd.googlegroups.com>
References: <hn4a5i$j1p$1@fred.mathworks.com>
NNTP-Posting-Host: 198.206.219.34
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1268100228 25425 127.0.0.1 (9 Mar 2010 02:03:48 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 9 Mar 2010 02:03:48 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: b5g2000prd.googlegroups.com; posting-host=198.206.219.34; 
	posting-account=_KeVcAoAAAB7j3xn35ujaQ0BoQhuzwJP
User-Agent: G2/1.0
X-HTTP-Via: 1.1 wwwproxy-son-ca-02.ca.sandia.gov:80 (squid/2.5.STABLE14)
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) 
	Gecko/20100115 Firefox/3.6,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:615130

On Mar 8, 6:01 pm, "Enosh Bale" <fergysonnai...@gmail.com> wrote:
> that, given a square matrix, returns the sum of the diagonal elements.

doc sum
doc diag


Ex:
>> A = magic(5)
A =
    17    24     1     8    15
    23     5     7    14    16
     4     6    13    20    22
    10    12    19    21     3
    11    18    25     2     9
>> diag(A)
ans =
    17
     5
    13
    21
     9
>> sum(diag(A))
ans =
    65

-Nathan