how do I remove special characters from my cell array strings?

조회 수: 2 (최근 30일)
Srishti Saha
Srishti Saha 2018년 4월 7일
댓글: Srishti Saha 2018년 4월 8일
I have a cell array of the sorts:
{'508-647-7000'} {' (508) 647-7001'} {' 617-555-1212'}
I need the special characters and the spaces removed from these. The result should look something like this:
{'5086477000'} {'5086477001'} {'6175551212'}
I tried writing the following cell function to do it:
characters = ['(',')',' ','-'];
s_nos=cellfun(@(x) x~=characters,s_split, 'UniformOutput', false);
but I am getting the following error: * Matrix dimensions must agree.*
Kindly help.
  댓글 수: 3
Rik
Rik 2018년 4월 8일
You can enter that solution as an answer and accept it.
You can also use isstrprop to keep only digits:
s_nos=cellfun(@(x) x(isstrprop(x,'digit')),s_split, 'UniformOutput', false);
Srishti Saha
Srishti Saha 2018년 4월 8일
Thanks Rik Wisselink

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

채택된 답변

Srishti Saha
Srishti Saha 2018년 4월 8일
This worked for me
s_nos=regexprep(s_split,'[^0-9]','');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by