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:
find elements

Subject: find elements

From: Wendy

Date: 26 Jan, 2010 11:22:03

Message: 1 of 3

Hi,

I have two cells:
A = {'212182_at'
    '210699_at'
    '201465_s_at'
    '206683_at'
    '201325_s_at'
    '203518_at'};

B = {'203518_at'
    '201325_s_at'
     '206683_at'
    '221558_s_at'
    '210184_at'
    '201566_x_at'
    '210699_at'};

How can I find the same elements between A and B? For example, '206683_at' occurs in both A and B. I want to output the position of '206683_at' in A. I know I can do this by looping through vector B, and do strcmp(B_i, A). Is there any function that can do the job better? Ideally, I am thinking if there is a function in matlab that compare two vectors at once.

Thank you.
Wendy

Subject: find elements

From: Jos (10584)

Date: 26 Jan, 2010 12:15:06

Message: 2 of 3

"Wendy " <wlq121@gmail.com> wrote in message <hjmj8r$lgb$1@fred.mathworks.com>...
<SNIP looking for set functions ...

help ismember
help intersect

Jos

Subject: find elements

From: us

Date: 26 Jan, 2010 12:15:06

Message: 3 of 3

"Wendy " <wlq121@gmail.com> wrote in message <hjmj8r$lgb$1@fred.mathworks.com>...
> Hi,
>
> I have two cells:
> A = {'212182_at'
> '210699_at'
> '201465_s_at'
> '206683_at'
> '201325_s_at'
> '203518_at'};
>
> B = {'203518_at'
> '201325_s_at'
> '206683_at'
> '221558_s_at'
> '210184_at'
> '201566_x_at'
> '210699_at'};
>
> How can I find the same elements between A and B? For example, '206683_at' occurs in both A and B. I want to output the position of '206683_at' in A. I know I can do this by looping through vector B, and do strcmp(B_i, A). Is there any function that can do the job better? Ideally, I am thinking if there is a function in matlab that compare two vectors at once.
>
> Thank you.
> Wendy

a hint:

     help ismember;

us

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