Path: news.mathworks.com!not-for-mail
From: "Sky Pelletier" <skytoddk@remove14chars.vet.upenn.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: newbie seeks vectorization help
Date: Sun, 11 May 2008 06:04:14 +0000 (UTC)
Organization: University of Pennsylvania
Lines: 56
Message-ID: <g0628u$qdp$1@fred.mathworks.com>
References: <g000e3$eoi$1@fred.mathworks.com> <g053lr$rss$1@fred.mathworks.com>
Reply-To: "Sky Pelletier" <skytoddk@remove14chars.vet.upenn.edu>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1210485854 27065 172.30.248.38 (11 May 2008 06:04:14 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 11 May 2008 06:04:14 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1380717
Xref: news.mathworks.com comp.soft-sys.matlab:467770


Roger,

totalfactor = S.*(K'*I);

is exactly what I was looking for!  Thank you!  I was
suffering from tunnel vision; having indexed into the matrix
K in an earlier version, I was focusing on how to use the
logical matrices S and I to index K, when in fact my
original idea was to use them as multiplicative masks--I
even call them S_mask and I_mask in my code!  An
intermediate  version had S and I as index vectors, and I
was trying so hard to figure out how to adjust that version
while still using them as indices that I missed the obvious.

and by the way, I think my loop actually doesn't work
because of how I misunderstood the matrix versus linear
indexing issue.  In any event, it wasn't giving the correct
answers when I left work Friday :)  I believe with a few
appropriate tweaks I should be able to get it working so I
can test which is actually faster, though I strongly suspect
the method you proposed will prove to be the winner.

Thank you so much.  I owe you a coke.

..Sky

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
wrote in message <g053lr$rss$1@fred.mathworks.com>...

>   In any event, when you say, "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", I assume that you meant if
S(n,m) is false (zero,) 
> then zero goes into the matrix at (n,m), regardless of
what sum from K is 
> obtained.  If so, the following is a possible
vectorization of this, though I am 
> not sure it is any faster than your for-loop method.
> 
>  totalfactor = S.*(K'*I);
> 
> The summation is done by the matrix product.  This uses
your logical arrays 
> as numerical arrays with 1's and 0's, so it is possible
you would need to 
> convert them explicitly to numerical type to work
properly, say with '+'.  I 
> don't know.  My own system doesn't know about logical
types and so has no 
> trouble with that.
> 
> Roger Stafford
>