mHelpMe
mHelpMe

Reputation: 6668

cell array remove the leading character in each cell

I have a 27 x 3 cell each cell contains text.

For some annoying reason the data I'm using has been saved with each cell starting with a ', how do I remove these?

Example of my data

   column 1    column 2   column 3
   'some       'text      'blah
   'more       'blah      'help

What I want

   column 1    column 2   column 3
   some       text      blah
   more       blah      help

Is the best way to use cellfun? If so how do you use it?

Upvotes: 0

Views: 516

Answers (2)

sco1
sco1

Reputation: 12214

Another option is to use regexprep:

c = {'''some' '''text' '''blah';
     '''more' '''blah' '''help'}; %// data
c = regexprep(c, '''', '');

Which also returns:

c = 

    'some'    'text'    'blah'
    'more'    'blah'    'help'

Upvotes: 1

Luis Mendo
Luis Mendo

Reputation: 112659

Use cellfun with a suitable anonymous function. The anonymous function should accept a string and remove its first character, so @(s) s(2:end):

c = {'''some' '''text' '''blah';
     '''more' '''blah' '''help'}; %// data
c = cellfun(@(s) s(2:end), c, 'uniformoutput', 0); %// remove first element of
                                                   %// each cell's contents

Result:

c = 
    'some'    'text'    'blah'
    'more'    'blah'    'help'

Upvotes: 3

Related Questions