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:
how to find indicies of points in a range

Subject: how to find indicies of points in a range

From: maribo bo

Date: 21 Oct, 2010 15:15:21

Message: 1 of 4

Hi everybody,

I wanted to ask a (hopefully) simple question. I found nowhere, how to find indicies of points of a matrix, which have properties to stay in a range. Better said with an example:

matrix A;
pointsInRange = find( 13 > A >8);

Let's say I have a matrix A, and I need to find all those elements which are in a range [8, 13]. This doesn't work to me.

So, does exist a way to do this?

Thank you very much for your attention and for your asnwers!

MariBo

Subject: how to find indicies of points in a range

From: Steven_Lord

Date: 21 Oct, 2010 15:21:10

Message: 2 of 4



"maribo bo" <marimao@blu.it> wrote in message
news:i9ple9$ig9$1@fred.mathworks.com...
> Hi everybody,
>
> I wanted to ask a (hopefully) simple question. I found nowhere, how to
> find indicies of points of a matrix, which have properties to stay in a
> range. Better said with an example:
>
> matrix A;
> pointsInRange = find( 13 > A >8);

This will always return an empty array pointsInRange.

The expression (13 > A > 8) is evaluated left-to-right. So first MATLAB
computes (13 > A) which results in a logical array (let's call it L for the
sake of argument) the same size as A where each element is either 0 (false)
or 1 (true). Then MATLAB uses L in the comparison (L > 8). Since neither 0
nor 1 are greater than 8, the result is is logical array the same size as A
containing all 0 (false) values.

> Let's say I have a matrix A, and I need to find all those elements which
> are in a range [8, 13]. This doesn't work to me.
>
> So, does exist a way to do this?

Do you explicitly need the _indices_ of those elements or do you just need
to be able to _refer_ to them?

Compute a logical array:

pointsInInterval = (8 < A) & (A < 13); % true if the element of A is greater
than 8 AND less than 13, false otherwise

If you just need to _refer_ to these points (as I suspect is the case), you
can use logical indexing.

A(pointsInInterval) = 2*A(pointsInInterval);

If you absolutely need the indices, use FIND on this logical array.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: how to find indicies of points in a range

From: Sean

Date: 21 Oct, 2010 15:24:34

Message: 3 of 4

"maribo bo" <marimao@blu.it> wrote in message <i9ple9$ig9$1@fred.mathworks.com>...
> Hi everybody,
>
> I wanted to ask a (hopefully) simple question. I found nowhere, how to find indicies of points of a matrix, which have properties to stay in a range. Better said with an example:
>
> matrix A;
> pointsInRange = find( 13 > A >8);
>
> Let's say I have a matrix A, and I need to find all those elements which are in a range [8, 13]. This doesn't work to me.
>
> So, does exist a way to do this?
>
> Thank you very much for your attention and for your asnwers!
>
> MariBo

matrix A;
pointsInRange = find( 13 > A & A >8);

Subject: how to find indicies of points in a range

From: someone

Date: 21 Oct, 2010 15:26:27

Message: 4 of 4

"maribo bo" <marimao@blu.it> wrote in message <i9ple9$ig9$1@fred.mathworks.com>...
> Hi everybody,
>
> I wanted to ask a (hopefully) simple question. I found nowhere, how to find indicies of points of a matrix, which have properties to stay in a range. Better said with an example:
>
> matrix A;
> pointsInRange = find( 13 > A >8);

% Try instead:
pointsInRange = find((8 < A) & (A < 13));

>
> Let's say I have a matrix A, and I need to find all those elements which are in a range [8, 13]. This doesn't work to me.
>
> So, does exist a way to do this?
>
> Thank you very much for your attention and for your asnwers!
>
> MariBo

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