How to remove single quotes using regexprep

I would like to know how can we eliminate the single quotes in a cell using regexprep. I have a 1x150000 cell array.

댓글 수: 4

vish
vish 2011년 2월 9일
I tried using three single quotes ''', its giving me an error.
Oleg Komarov
Oleg Komarov 2011년 2월 9일
Are you sure it's not just the visualization effect when you try to display a cell array of string on the command window.
Ex: a = {'hi'}
vish
vish 2011년 2월 9일
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 2011년 2월 9일
Then Andrew's code should work fine.

댓글을 달려면 로그인하십시오.

 채택된 답변

Jan
Jan 2011년 2월 9일

7 개 추천

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

David Young
David Young 2011년 2월 9일
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 2018년 3월 2일
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

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

David Young
David Young 2011년 2월 9일

1 개 추천

The solution using regexprep is just
D = regexprep(C, '''', '');
Lakhan
Lakhan 2013년 11월 8일

0 개 추천

its not working in my case
if true
% code
>> a = {'hi'}
a =
'hi'
>> D = strrep(a, '''', '')
D =
'hi'
end

댓글 수: 1

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}

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

질문:

2011년 2월 9일

댓글:

2018년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by