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:
Search in a cell array with strings and number

Subject: Search in a cell array with strings and number

From: Yersinio Jimenez Campos

Date: 1 Jul, 2009 15:29:01

Message: 1 of 3

Hello.

I have a cell array with strings and numbers like that:

A= {'BANK CODE 'TRANS CODE' 'COST';
       'BRSJE' 'b-8' 1349 ;
       'BRSJE' 'b-2' 3670
    }

Now i want to search some elements in A, for example search the occurence of 'BRSJE' in the cell array A,and in other ocations i want to search which cost are lower than 3000.

Regards
Yersinio.

Subject: Search in a cell array with strings and number

From: Dave Brackett

Date: 29 Jul, 2009 23:23:02

Message: 2 of 3

"Yersinio Jimenez Campos" <yersinioj@hotmail.com> wrote in message <h2fvbt$ar4$1@fred.mathworks.com>...
> Hello.
>
> I have a cell array with strings and numbers like that:
>
> A= {'BANK CODE 'TRANS CODE' 'COST';
> 'BRSJE' 'b-8' 1349 ;
> 'BRSJE' 'b-2' 3670
> }
>
> Now i want to search some elements in A, for example search the occurence of 'BRSJE' in the cell array A,and in other ocations i want to search which cost are lower than 3000.
>
> Regards
> Yersinio.

% to search for occurence of 'BRSJE' you could use:
>> strcmp('BRSJE',A)
ans =
     0 0 0
     1 0 0
     1 0 0

% to find the positions in the cell of the values lower than 3000 you could use:
B={A{2:end,3}}
C=cell2mat(B)
[row,col]=find(C<3000)

Hope that helps

Subject: Search in a cell array with strings and number

From: Yersinio Jimenez

Date: 31 Jul, 2009 13:31:01

Message: 3 of 3

I try your solution and works fine.
Thanks.
Yersinio.

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