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 of cell containing characters

Subject: find elements of cell containing characters

From: Pr B

Date: 20 Mar, 2011 05:31:04

Message: 1 of 5

i have a cell array a= {'1' 'abc' '234' 'asdfasdfw'} and i want to find the elements of this cell that contain characters. i'm trying to use ischar, but that gives me a 1 flag for every element in the cell (e.g. ischar(a{1}). is there a way to do this?

Subject: find elements of cell containing characters

From: Nasser M. Abbasi

Date: 20 Mar, 2011 05:41:18

Message: 2 of 5

On 3/19/2011 10:31 PM, Pr B wrote:
> i have a cell array a= {'1' 'abc' '234' 'asdfasdfw'} and i want to find the elements of this
> cell that contain characters. i'm trying to use ischar, but that gives me a 1 flag for every
> element in the cell (e.g. ischar(a{1}). is there a way to do this?


It gives you 1 for each cell becuase '1' is indeed a character.

--Nasser

Subject: find elements of cell containing characters

From: Oleg Komarov

Date: 20 Mar, 2011 05:44:04

Message: 3 of 5

"Pr B" <pb2297@columbia.edu> wrote in message <im43eo$de2$1@fred.mathworks.com>...
> i have a cell array a= {'1' 'abc' '234' 'asdfasdfw'} and i want to find the elements of this cell that contain characters. i'm trying to use ischar, but that gives me a 1 flag for every element in the cell (e.g. ischar(a{1}). is there a way to do this?


a = {'1' 'abc' '234' 'asdfasdfw'};
cellfun(@(x) ~all(ismember(x,48:57)),a)

Your cell array contains number in string form, i.e. '1' corresponds to a 49.
Look at the ascii table to understand the conversion or simply type char((48:57).').

Oleg

Subject: find elements of cell containing characters

From: Pr B

Date: 20 Mar, 2011 05:48:04

Message: 4 of 5

well i guess what i mean then is if that element of the cell contains letters!

Subject: find elements of cell containing characters

From: Loren Shure

Date: 21 Mar, 2011 12:18:34

Message: 5 of 5


"Pr B" <pb2297@columbia.edu> wrote in message
news:im44ek$rr0$1@fred.mathworks.com...
> well i guess what i mean then is if that element of the cell contains
> letters!
>

Check out the isletter function in conjunction with cellfun perhaps.

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

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