Thread Subject: num2cellstr

Subject: num2cellstr

From: Jason S

Date: 28 Oct, 2008 20:21:01

Message: 1 of 4

is there a function that converts an array of numbers to a cell array
of strings?
num2cell converts array of numbers -> cell array of numbers
num2str converts array of numbers -> char array (but not cell array)

I suppose I can do this easily, it just seems like an obvious idea for
a builtin function

Subject: num2cellstr

From: Walter Roberson

Date: 28 Oct, 2008 21:20:04

Message: 2 of 4

Jason S <jmsachs@gmail.com> wrote in message <eb6328b2-f07e-44c5-a225-f9ea5bee1408@u29g2000pro.googlegroups.com>...
> is there a function that converts an array of numbers to a cell array
> of strings?

No.

> num2cell converts array of numbers -> cell array of numbers
> num2str converts array of numbers -> char array (but not cell array)

cellfun(@num2str,num2cell(TheMatrix),'Uniform',0)

Subject: num2cellstr

From: Praetorian

Date: 28 Oct, 2008 21:23:47

Message: 3 of 4

On Oct 28, 2:21=A0pm, Jason S <jmsa...@gmail.com> wrote:
> is there a function that converts an array of numbers to a cell array
> of strings?
> num2cell converts array of numbers -> cell array of numbers
> num2str converts array of numbers -> char array (but not cell array)
>
> I suppose I can do this easily, it just seems like an obvious idea for
> a builtin function

AFAIK there is no single function that can do this but as you said
it's easy enough to create your own:

>> data =3D num2cell([1:5]);
>> data =3D cellfun(@num2str,data,'UniformOutput',false)

data =3D

    '1' '2' '3' '4' '5'

HTH,
Ashish.

Subject: num2cellstr

From: Jos

Date: 28 Oct, 2008 21:27:01

Message: 4 of 4

Jason S <jmsachs@gmail.com> wrote in message <eb6328b2-f07e-44c5-a225-f9ea5bee1408@u29g2000pro.googlegroups.com>...
> is there a function that converts an array of numbers to a cell array
> of strings?
> num2cell converts array of numbers -> cell array of numbers
> num2str converts array of numbers -> char array (but not cell array)
>
> I suppose I can do this easily, it just seems like an obvious idea for
> a builtin function

what about:

data = rand(3,4)
CS = reshape(cellstr(num2str(A(:))),size(A))

hth
Jos

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com