Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Multi Dimensional Indexing
Date: Mon, 19 Apr 2010 00:42:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 9
Message-ID: <hqg8ss$nfi$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1271637725 24050 172.30.248.38 (19 Apr 2010 00:42:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 19 Apr 2010 00:42:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2264149
Xref: news.mathworks.com comp.soft-sys.matlab:627706

I was hoping someone could help me out.  I'm happy enough (I think) with using something like

R(R > 0) = 0;

when I want to 'zero-out' all the positive elements of a vector.  But how do I generalise this idea?  To give a more specific example, suppose I have

r = rand(4, 5, 6, 7);

and I want to zero-out all the occasions where, say, sum(r(:, :, 1:3, :), 3) > sum(r(:, :, 4:6, :), 3).  I can't work out how to do such a thing.