Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Multi Dimensional Indexing

Subject: Multi Dimensional Indexing

From: james bejon

Date: 19 Apr, 2010 00:42:05

Message: 1 of 3

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.

Subject: Multi Dimensional Indexing

From: Roger Stafford

Date: 19 Apr, 2010 01:40:21

Message: 2 of 3

"james bejon" <jamesbejon@yahoo.co.uk> wrote in message <hqg8ss$nfi$1@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

Subject: Multi Dimensional Indexing

From: james bejon

Date: 19 Apr, 2010 17:23:04

Message: 3 of 3

Of course. Thanks Roger.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us