Got Questions? Get Answers.
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:
to identify a vector

Subject: to identify a vector

From: sk maidul haque

Date: 31 Dec, 2010 06:26:03

Message: 1 of 5


I have two vectors a and b; There is one element c which either belongs to a or b. How to know which vector does the element c belong to?

Subject: to identify a vector

From: Matt Fig

Date: 31 Dec, 2010 06:57:04

Message: 2 of 5

any(c==a)
any(c==b)

Also, see ISMEMBER

Subject: to identify a vector

From: Yumnam Kirani

Date: 31 Dec, 2010 08:20:20

Message: 3 of 5

simply subtact c from the vectors and see whether any zero element occurs in any of the vectors. The vector which has zero as an element is the one which contains c.

Yumnam Kirani Singh
Tronglaobi Awang Leikai

"sk maidul haque" <skmaidulhaque@gmail.com> wrote in message <ifjt1r$s9n$1@fred.mathworks.com>...
>
> I have two vectors a and b; There is one element c which either belongs to a or b. How to know which vector does the element c belong to?

Subject: to identify a vector

From: Yumnam Kirani

Date: 31 Dec, 2010 08:21:04

Message: 4 of 5

simply subtact c from the vectors and see whether any zero element occurs in any of the vectors. The vector which has zero as an element is the one which contains c.

Yumnam Kirani Singh
Tronglaobi Awang Leikai

"sk maidul haque" <skmaidulhaque@gmail.com> wrote in message <ifjt1r$s9n$1@fred.mathworks.com>...
>
> I have two vectors a and b; There is one element c which either belongs to a or b. How to know which vector does the element c belong to?

Subject: to identify a vector

From: Walter Roberson

Date: 31 Dec, 2010 08:29:27

Message: 5 of 5

On 31/12/10 2:20 AM, Yumnam Kirani wrote:
> simply subtact c from the vectors and see whether any zero element
> occurs in any of the vectors. The vector which has zero as an element is
> the one which contains c.
> Yumnam Kirani Singh
> Tronglaobi Awang Leikai
>
> "sk maidul haque" <skmaidulhaque@gmail.com> wrote in message
> <ifjt1r$s9n$1@fred.mathworks.com>...
>>
>> I have two vectors a and b; There is one element c which either
>> belongs to a or b. How to know which vector does the element c belong to?

I think that solution is likely to take longer than

ismember(c, a)

(a false result from which would imply that c is in b, as we are told it
is in one or the other.)


Possibly, though,

any(c==a)

might be faster.

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