From: Young Ryu on
Hi

I have the following three arrays:

A{1}='abc_12341';
A{2}='abc_21313';
A{3}='abc_13511';

Here, I'd like to change abc to def. How can I do this without using "for..."?
I tried this but not wored:

A{:}(1:3)='def';

Thanks!
From: Nathan on
On Mar 5, 1:50 pm, "Young Ryu" <ryuy...(a)gmail.com> wrote:
> Hi
>
> I have the following three arrays:
>
> A{1}='abc_12341';
> A{2}='abc_21313';
> A{3}='abc_13511';
>
> Here, I'd like to change abc to def. How can I do this without using "for...."?
> I tried this but not wored:
>
> A{:}(1:3)='def';
>
> Thanks!

How about using cellfun:

cellfun(@(x)['def',x(4:end)],A,'un',0)

-Nathan
From: Matt Fig on
One approach:

B = regexprep(A,'abc','def')
From: Jos (10584) on
"Young Ryu" <ryuyr77(a)gmail.com> wrote in message <hmrub1$cb0$1(a)fred.mathworks.com>...
> Hi
>
> I have the following three arrays:
>
> A{1}='abc_12341';
> A{2}='abc_21313';
> A{3}='abc_13511';
>
> Here, I'd like to change abc to def. How can I do this without using "for..."?
> I tried this but not wored:
>
> A{:}(1:3)='def';
>
> Thanks!

strrep(A,'abc','def')

or use regular expressions, for instance:

regexprep(A,'^abc','def')

hth
Jos