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:
Searching cell array of numbers

Subject: Searching cell array of numbers

From: Liana

Date: 26 Oct, 2011 19:07:11

Message: 1 of 3

Hello,

I need to find a numerical value in cell array:

cont(1) = {1}; cont(2) = {5}; cont(3) = {8};
ind = find(ismember(cont, 'string1')==5)

What should be written instead of 'string1' to define cell array of numbers? I am expecting to get ind = 2.

Thanks.

Subject: Searching cell array of numbers

From: Bruno Luong

Date: 27 Oct, 2011 06:20:31

Message: 2 of 3

"Liana" wrote in message <j89lov$67l$1@newscl01ah.mathworks.com>...
> Hello,
>
> I need to find a numerical value in cell array:
>
> cont(1) = {1}; cont(2) = {5}; cont(3) = {8};
> ind = find(ismember(cont, 'string1')==5)

>
> What should be written instead of 'string1' to define cell array of numbers? I am expecting to get ind = 2.

why not using
find([cont{:}] == 5)

I don't understand why you use ISMEMBER with string on numerical data.

Bruno

Subject: Searching cell array of numbers

From: Liana

Date: 27 Oct, 2011 09:24:14

Message: 3 of 3

Thank you. Yes, I mentioned 'string' only as an example, because I did not know how to use ismember for numerical values. It was my question:) But your solution works fine. Thanks again.

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j8at7f$5cn$1@newscl01ah.mathworks.com>...
> "Liana" wrote in message <j89lov$67l$1@newscl01ah.mathworks.com>...
> > Hello,
> >
> > I need to find a numerical value in cell array:
> >
> > cont(1) = {1}; cont(2) = {5}; cont(3) = {8};
> > ind = find(ismember(cont, 'string1')==5)
>
> >
> > What should be written instead of 'string1' to define cell array of numbers? I am expecting to get ind = 2.
>
> why not using
> find([cont{:}] == 5)
>
> I don't understand why you use ISMEMBER with string on numerical data.
>
> Bruno

Tags for this Thread

No tags are associated with 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