|
|
chaning a part of cell arrays
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!
|
|
0
|
|
|
|
Reply
|
Young
|
3/5/2010 9:50:25 PM |
|
On Mar 5, 1:50=A0pm, "Young Ryu" <ryuy...@gmail.com> wrote:
> Hi
>
> I have the following three arrays:
>
> A{1}=3D'abc_12341';
> A{2}=3D'abc_21313';
> A{3}=3D'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)=3D'def';
>
> Thanks!
How about using cellfun:
cellfun(@(x)['def',x(4:end)],A,'un',0)
-Nathan
|
|
0
|
|
|
|
Reply
|
Nathan
|
3/5/2010 9:56:19 PM
|
|
One approach:
B = regexprep(A,'abc','def')
|
|
0
|
|
|
|
Reply
|
Matt
|
3/5/2010 10:00:22 PM
|
|
"Young Ryu" <ryuyr77@gmail.com> wrote in message <hmrub1$cb0$1@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
|
|
0
|
|
|
|
Reply
|
Jos
|
3/5/2010 10:01:21 PM
|
|
|
3 Replies
241 Views
(page loaded in 0.738 seconds)
|
|
|
|
|
|
|
|
|