white space in cell array

조회 수: 7 (최근 30일)
Jack_111
Jack_111 2013년 7월 23일
am using textscan to read text file and I get <55x1 cell> examples:
'aa a aa'
'a aaaa a'
'a = aaaaa'
'aaaaaa'
' a a a aaa'
'aa'
'aaa'
'aaaa'
.
.
.
.
I want to delete the white spaces in each sting. for example, If I have a sting
string = 'I am 24 Years old'
And I use
string(ismember(string,' ')) = [];
it will eliminate the spaces and I will get
'Iam24Yearsold'
But with the cell doesn't work or I don't know how to do it How can I do that? any suggestions please?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 7월 23일
편집: Andrei Bobrov 2013년 7월 23일
string = 'I am 24 Years old';
strrep(string,' ','');
for cell array
string = {'I am 24 Years old';'I am 24 Years old'}
strrep(string,' ','');
  댓글 수: 3
Andrei Bobrov
Andrei Bobrov 2013년 7월 23일
see 'for cell..' part in my answer
Jan
Jan 2013년 7월 23일
+1: STRREP operates on cell directly.

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 23일
s={'aa a aa'; 'a aaaa a'; 'a = aaaaa'}
out=cellfun(@(x) x(~ismember(x,' ')),s,'un',0)
  댓글 수: 1
Jan
Jan 2013년 7월 23일
A simplification:
cellfun(@(x) x(x~=' ')), s, 'un', 0)

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by