From: james bejon on
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.
From: Roger Stafford on
"james bejon" <jamesbejon(a)yahoo.co.uk> wrote in message <hqg8ss$nfi$1(a)fred.mathworks.com>...
> 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.

I would think it would be something like this:

t = sum(r(:,:,1:3,:),3)>sum(r(:,:,4:6,:),3);
r(repmat(t,1,1,6,1)) = 0;

Roger Stafford
From: james bejon on
Of course. Thanks Roger.