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

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
vector indexing sp... ibrahim 19 Apr, 2010 13:28:06
indexing james bejon 18 Apr, 2010 20:44:06
dimensional james bejon 18 Apr, 2010 20:44:06
sub2ind james bejon 18 Apr, 2010 20:44:06
multi james bejon 18 Apr, 2010 20:44:06
rssFeed for this Thread

Contact us