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:
Cell array Conversion

Subject: Cell array Conversion

From: Garrett

Date: 13 Aug, 2010 19:45:05

Message: 1 of 4

Hey guys,

I need to convert a 1 dimensional cell array of numbers that are in string format to an integer format.

example:

'1'
'2'
'3'

would be the cell array and we just want it to be
1
2
3

Any advice would be appreciated.

Subject: Cell array Conversion

From: Sean

Date: 13 Aug, 2010 20:01:22

Message: 2 of 4

"Garrett " <bantong@onid.orst.edu> wrote in message <i447c1$g83$1@fred.mathworks.com>...
> Hey guys,
>
> I need to convert a 1 dimensional cell array of numbers that are in string format to an integer format.
>
> example:
>
> '1'
> '2'
> '3'
>
> would be the cell array and we just want it to be
> 1
> 2
> 3
>
> Any advice would be appreciated.


One way:
cellfun(@(x)str2num(x),A)

Subject: Cell array Conversion

From: Andy

Date: 13 Aug, 2010 20:04:04

Message: 3 of 4

"Garrett " <bantong@onid.orst.edu> wrote in message <i447c1$g83$1@fred.mathworks.com>...
> Hey guys,
>
> I need to convert a 1 dimensional cell array of numbers that are in string format to an integer format.
>
> example:
>
> '1'
> '2'
> '3'
>
> would be the cell array and we just want it to be
> 1
> 2
> 3
>
> Any advice would be appreciated.

I'm pretty sure str2double will do this correctly.

Subject: Cell array Conversion

From: Garrett

Date: 13 Aug, 2010 20:15:23

Message: 4 of 4

Thanks Sean worked like a charm!

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