COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### chaning a part of cell arrays

• Follow

```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

```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!

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

-Nathan
```
 0

```One approach:

B = regexprep(A,'abc','def')
```
 0

```"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

3 Replies
241 Views

Similiar Articles:

7/24/2012 4:53:44 PM