Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

converting from dataset (statistics toolbox) to cell array

35 views
Skip to first unread message

ade77

unread,
Jul 1, 2010, 9:40:22 AM7/1/10
to
I have a varibale A, of dataset class (250 by 1), the contents are all string. I need to convert that into a cell array of (250 by 1), unfortunately there seems to be no built in function for this.

I tried cellstr in the documentation under dataset, but error.

Any hint.

Peter Perkins

unread,
Jul 1, 2010, 10:28:40 AM7/1/10
to
On 7/1/2010 9:40 AM, ade77 wrote:
> I have a varibale A, of dataset class (250 by 1), the contents are all
> string. I need to convert that into a cell array of (250 by 1),
> unfortunately there seems to be no built in function for this.

You might have one of two things:

1) a dataset with a variable that's a char matrix
2) a dataset with a variable that's already a cellstr

In either case, if all you want to do is get one variable out and
convert it to a cell array of strings, you can just use the dataset's
dot subscripting to pick out the variable and convert it if necessary.

Case 1:
>> ds = dataset(['abc';'def';'ghi'])
ds =
Var1
abc
def
ghi
>> s = cellstr(ds.Var1)
s =
'abc'
'def'
'ghi'
In this case, it might make more sense to just convert it in place:
>> ds.Var1 = cellstr(ds.Var1)
ds =
Var1
'abc'
'def'
'ghi'
>> summary(ds)
Var1: [3x1 cell string]

Case 2:
>> ds = dataset({'abc';'def';'ghi'})
ds =
Var1
'abc'
'def'
'ghi'
>> s = ds.Var1
s =
'abc'
'def'
'ghi'
In this case, there's really no need to take it out of the array,
because you can refer to ds.Var1, and that _is_ a cell array of strings.

There is cellstr method for dataset that should do this for you:

>> cellstr(ds)
ans =
'abc'
'def'
'ghi'

So the fact that you said

> I tried cellstr in the documentation under dataset, but error.

makes me wonder what else is in that array.

ade77

unread,
Jul 1, 2010, 2:11:09 PM7/1/10
to
Peter Perkins <Peter....@MathRemoveThisWorks.com> wrote in message <i0i8mo$9ho$1...@fred.mathworks.com>...

Deep appreciation Perkins

0 new messages