Thread Subject: copying multiple cells (strings) inside a cell array

Subject: copying multiple cells (strings) inside a cell array

From: Michael Ashby

Date: 24 Apr, 2009 17:29:02

Message: 1 of 3

I have a cell array containing strings and want to do a simple copy of the strings in some cells into other cells. Can this be done with indexing or cellfun or a loop?

e.g.
% copy all the cells containing "z" into the cells one before the "z" cells.

a = {'a','b','z','b','a','z'};
  
copy_cells = find(strcmp('z',a)); % indices of cells to be copied
target_cells = copy_cells-1; % indices of cells to be pasted into

result should read

a = {'a','z','z','b','z','z'};

I am sure there is a simple way to achieve this result, but I can not seem to get to it.
Any help is greatly appreciated.

Mike

Subject: copying multiple cells (strings) inside a cell array

From: Matt Fig

Date: 24 Apr, 2009 17:56:01

Message: 2 of 3

a(target_cells) = {'z'}

Subject: copying multiple cells (strings) inside a cell array

From: Michael Ashby

Date: 24 Apr, 2009 18:08:02

Message: 3 of 3

"Matt Fig" <spamanon@yahoo.com> wrote in message <gssufh$jid$1@fred.mathworks.com>...
> a(target_cells) = {'z'}

Thanks

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
cell array Michael Ashby 24 Apr, 2009 13:30:21
indexing Michael Ashby 24 Apr, 2009 13:30:21
rssFeed for this Thread

Contact us at files@mathworks.com