Path: news.mathworks.com!not-for-mail
From: "Sky Pelletier" <skytoddk@remove14chars.vet.upenn.edu>
Newsgroups: comp.soft-sys.matlab
Subject: newbie seeks vectorization help
Date: Thu, 8 May 2008 22:56:03 +0000 (UTC)
Organization: University of Pennsylvania
Lines: 30
Message-ID: <g000e3$eoi$1@fred.mathworks.com>
Reply-To: "Sky Pelletier" <skytoddk@remove14chars.vet.upenn.edu>
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 1210287363 15122 172.30.248.37 (8 May 2008 22:56:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 8 May 2008 22:56:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1380717
Xref: news.mathworks.com comp.soft-sys.matlab:467509


I am brand-spanking new to vectorizing code.  Forgive my
ignorance.

N indicates number of nodes.
M indicates number of simulations.

K = an N x N matrix of pre-calculated between-node
interaction values for this application. 

I have two N x M logical matrices, S and I, where a 1 in
position (n,m) indicates that in simulation M, node n is
active in set S or I as appropriate.  The goal is to
generate an N x M matrix in which element (n,m) is the sum
of effect of all active nodes in I on the n'th node in S,
for simulation M.

my code is like:

totalfactor = zeros(N,M);

for simnumber = 1:M
  totalfactor(:,simnumber) = sum( K( I(:, simnumber), S(:,
simnumber), 1);
end

I KNOW there is a more elegant (and faster!) way to do this,
but I am just learning this vectorization and my brain is
having a hard time switching from the looping I'm used to.

Thank you for your help!  I'm not used to feeling so ignorant!