Thread Subject: find function

Subject: find function

From: Branko

Date: 5 Jan, 2009 13:00:05

Message: 1 of 6

Let's say that I have a random matrix:
A=ceil(randn(10,1));
and I want to find -1 and 2 values in the matrix. Which is done by following command
a=find(A==-1);
b=find(A==2);
However I' d like to use single command which in this case is:
c=find(A==-1 & A==2);
But I got empty matrix.Where is the cache.
Thanks.

Subject: find function

From: tpl@eng.cam.ac.uk (Tim Love)

Date: 5 Jan, 2009 13:06:28

Message: 2 of 6

"Branko" <branko_b@hotmail.com> writes:

>Let's say that I have a random matrix:
>A=ceil(randn(10,1));
>and I want to find -1 and 2 values in the matrix. Which is done by following command
>a=find(A==-1);
>b=find(A==2);
>However I' d like to use single command which in this case is:
>c=find(A==-1 & A==2);
>But I got empty matrix.Where is the cache.
The catch? You need OR, not AND, so you need | rather than &

Subject: find function

From: Jiro Doke

Date: 5 Jan, 2009 13:09:01

Message: 3 of 6

"Branko" <branko_b@hotmail.com> wrote in message <gjt08k$mt1$1@fred.mathworks.com>...
> Let's say that I have a random matrix:
> A=ceil(randn(10,1));
> and I want to find -1 and 2 values in the matrix. Which is done by following command
> a=find(A==-1);
> b=find(A==2);
> However I' d like to use single command which in this case is:
> c=find(A==-1 & A==2);
> But I got empty matrix.Where is the cache.
> Thanks.

That's because a number cannot be both -1 AND 2. Are you perhaps looking for either -1 OR 2?

Then do

c = find(A==-1 | A==2);


jiro

Subject: find function

From: us

Date: 5 Jan, 2009 13:10:20

Message: 4 of 6

"Branko"
> A=ceil(randn(10,1));
> and I want to find -1 and 2 values in the matrix. Which is done by following command
> c=find(A==-1 & A==2);
> But I got empty matrix.Where is the cache...

one of the solutions

     m=ceil(randn(10,1));
     r=find(m==-1 | m==2)
% r = 4 9 % <- based on random data...

us

Subject: find function

From: Matt Fig

Date: 5 Jan, 2009 13:13:02

Message: 5 of 6

Look at the | operator.

Subject: find function

From: Loren Shure

Date: 6 Jan, 2009 12:50:28

Message: 6 of 6

In article <gjt08k$mt1$1@fred.mathworks.com>, branko_b@hotmail.com
says...
> Let's say that I have a random matrix:
> A=ceil(randn(10,1));
> and I want to find -1 and 2 values in the matrix. Which is done by following command
> a=find(A==-1);
> b=find(A==2);
> However I' d like to use single command which in this case is:
> c=find(A==-1 & A==2);
> But I got empty matrix.Where is the cache.
> Thanks.
>

will ismember help you out?

--
Loren
http://blogs.mathworks.com/loren

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
code us 5 Jan, 2009 08:15:05
randn us 5 Jan, 2009 08:15:05
find us 5 Jan, 2009 08:15:05
or us 5 Jan, 2009 08:15:05
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com