"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 lefttoright. 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.softsys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
