From: CLou on
"Jos (10584) " <#10584(a)fileexchange.com> wrote in message <i0g37s$7rm$1(a)fred.mathworks.com>...
> "CLou " <cathy(a)prismstoneconsultingTO.com> wrote in message <i0g266$s6s$1(a)fred.mathworks.com>...
> > Hi,
> >
> > I'm trying to concat a string to each string in a cell array of strings using:
> >
> > first = 'first_'
> > attach = { 'end' 'end1' 'end31' }
> > i=1:1:size(attach,2)
> > cellfun( @(x) [first x(i) ], attach, 'UniformOutput',false)
> >
> > It works, except that all of the values in attach are truncated to 'end'. How do I prevent that from happening?
> >
> > Thanks!
> >
> > Cathy
>
> Why do it the hard way? ML offers some excellent string functions, like STRCAT:
>
> first = 'first_'
> attach = { 'end' 'end1' 'end31' }
> result = strcat(first,attach)
>
> hth
> Jos

Thanks, Jos
From: CLou on
"CLou " <cathy(a)prismstoneconsultingTO.com> wrote in message <i0g3fa$mkr$1(a)fred.mathworks.com>...
> "Jos (10584) " <#10584(a)fileexchange.com> wrote in message <i0g37s$7rm$1(a)fred.mathworks.com>...
> > "CLou " <cathy(a)prismstoneconsultingTO.com> wrote in message <i0g266$s6s$1(a)fred.mathworks.com>...
> > > Hi,
> > >
> > > I'm trying to concat a string to each string in a cell array of strings using:
> > >
> > > first = 'first_'
> > > attach = { 'end' 'end1' 'end31' }
> > > i=1:1:size(attach,2)
> > > cellfun( @(x) [first x(i) ], attach, 'UniformOutput',false)
> > >
> > > It works, except that all of the values in attach are truncated to 'end'. How do I prevent that from happening?
> > >
> > > Thanks!
> > >
> > > Cathy
> >
> > Why do it the hard way? ML offers some excellent string functions, like STRCAT:
> >
> > first = 'first_'
> > attach = { 'end' 'end1' 'end31' }
> > result = strcat(first,attach)
> >
> > hth
> > Jos
>
> Thanks, Jos
....should also say this code is taken from a larger body of code where I was already using vectorization for other manipulations. Guess I got carried away... :)