Path: news.mathworks.com!not-for-mail
From: "Kevin Sheppard" <kevin.you.know.what.to.do.sheppard@economics.ox.ac.uk>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Bogey
Date: Sat, 25 Oct 2008 18:01:25 +0000 (UTC)
Organization: Univ of Oxford
Lines: 9
Message-ID: <gdvmtl$nfu$1@fred.mathworks.com>
References: <gdvjlp$kij$1@fred.mathworks.com>
Reply-To: "Kevin Sheppard" <kevin.you.know.what.to.do.sheppard@economics.ox.ac.uk>
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 1224957685 24062 172.30.248.37 (25 Oct 2008 18:01:25 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 25 Oct 2008 18:01:25 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 514583
Xref: news.mathworks.com comp.soft-sys.matlab:497222


I'm not sure it will help performance, but you could get rid of one of the loops with repmat.  

for i = 1:2,
     tot = tot + X*repmat(Y(i,:),2,1);
end

Algebraically there are simple expressions for sums like these involving Kronecker products with identity matrices.  

These perform badly in code since they involve multiplying very sparse matrices (and allocating large matrices, or using splapack rather than blas).