From: jens on
Hello Matlab users

Example:

If I have a vector like countvector:

countvector=[]

countvector=[ countvector 1]

countvector=[ countvector 2]

Is there anyway to make a cellarray that do the same with strings like 'string1', 'string2 ', 'string3'........Instead of numeric data in a vector like the countvector?

Best Regards

Jens
From: Matt J on
"jens " <storebonghoved(a)hotmail.com> wrote in message <hkcj5p$m3i$1(a)fred.mathworks.com>...

> Is there anyway to make a cellarray that do the same with strings like 'string1', 'string2 ', 'string3'........Instead of numeric data in a vector like the countvector?
================

Yes, although in both cases the practice is strongly discouraged (you should preallocate your arrays)

>> stringcell={};
>> stringcell=[stringcell {'string1'}],

stringcell =

'string1'

>> stringcell=[stringcell {'string2'}],

stringcell =

'string1' 'string2'
From: Matt J on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hkcjog$slj$1(a)fred.mathworks.com>...

> >> stringcell={};
> >> stringcell=[stringcell {'string1'}],
>
> stringcell =
>
> 'string1'
>
> >> stringcell=[stringcell {'string2'}],
>
> stringcell =
>
> 'string1' 'string2'
===============================

In fact, you don't even need to use braces:


>> stringcell={};
>> stringcell=[stringcell 'string1'],

stringcell =

'string1'

>> stringcell=[stringcell 'string2'],

stringcell =

'string1' 'string2'
From: jens on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hkcn6n$7ml$1(a)fred.mathworks.com>...
> "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <hkcjog$slj$1(a)fred.mathworks.com>...
>
> > >> stringcell={};
> > >> stringcell=[stringcell {'string1'}],
> >
> > stringcell =
> >
> > 'string1'
> >
> > >> stringcell=[stringcell {'string2'}],
> >
> > stringcell =
> >
> > 'string1' 'string2'
> ===============================
>
> In fact, you don't even need to use braces:
>
>
> >> stringcell={};
> >> stringcell=[stringcell 'string1'],
>
> stringcell =
>
> 'string1'
>
> >> stringcell=[stringcell 'string2'],
>
> stringcell =
>
> 'string1' 'string2'

Thank you very much Matt

Best Regards

Jens