From: ade77 on
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.
From: Peter Perkins on
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.
From: ade77 on
Peter Perkins <Peter.Perkins(a)MathRemoveThisWorks.com> wrote in message <i0i8mo$9ho$1(a)fred.mathworks.com>...
> 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.

Deep appreciation Perkins