Path: news.mathworks.com!not-for-mail
From: "Rajgopal " <runraj@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Trace array of matrices
Date: Thu, 13 Aug 2009 20:43:03 +0000 (UTC)
Organization: Duisenberg School of Finance
Lines: 16
Message-ID: <h61tsn$lbo$1@fred.mathworks.com>
Reply-To: "Rajgopal " <runraj@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1250196183 21880 172.30.248.37 (13 Aug 2009 20:43:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Aug 2009 20:43:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1843774
Xref: news.mathworks.com comp.soft-sys.matlab:563227


Hi,

Is it possible to vectorize the sum of the trace of an array of 2-D matrices?

Currently I am doing it in a loop

A = ones(4,4,N)
sum = 0;
for i = 1:N
 sum = sum + trace(A(:,:,i))
end

Any suggestions?

Thanks a lot..
Purpose - speed...since N is huge!