How to remove single quotes using regexprep

34 vues (au cours des 30 derniers jours)
vish
vish le 9 Fév 2011
Commenté : Manoj le 2 Mar 2018
I would like to know how can we eliminate the single quotes in a cell using regexprep. I have a 1x150000 cell array.
  4 commentaires
vish
vish le 9 Fév 2011
ohh. Now I know what you mean. I am getting the single quotes only for few elements. Rest of them are as I desire.
Oleg Komarov
Oleg Komarov le 9 Fév 2011
Then Andrew's code should work fine.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 9 Fév 2011
STRREP is easier than REGEXPREP and needs the half processing time:
D = strrep(C, '''', '');
If the worm of quotes looks ugly, use:
D = strrep(C, char(39), '');
  2 commentaires
David Young
David Young le 9 Fév 2011
Yes, strrep is far faster than regexprep on my test. How disappointing that regexprep doesn't recognise that it has this simple case and process it as fast as strrep does.
Manoj
Manoj le 2 Mar 2018
how to remove NAN and single quotes in case of cell array of matrix? And I want to convert that cell array in to matrix form? help me

Connectez-vous pour commenter.

Plus de réponses (2)

David Young
David Young le 9 Fév 2011
The solution using regexprep is just
D = regexprep(C, '''', '');

Lakhan
Lakhan le 8 Nov 2013
its not working in my case
if true
% code
>> a = {'hi'}
a =
'hi'
>> D = strrep(a, '''', '')
D =
'hi'
end
  1 commentaire
Walter Roberson
Walter Roberson le 8 Nov 2013
Your string does not contain quotation marks. You have created a cell array, and string elements of a cell array are displayed surrounded by quote marks. Look at
a{1}

Connectez-vous pour commenter.

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by