white space in cell array

21 views (last 30 days)
Jack_111 on 23 Jul 2013
am using textscan to read text file and I get <55x1 cell> examples:
'aa a aa'
'a aaaa a'
'a = aaaaa'
' a a a aaa'
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
But with the cell doesn't work or I don't know how to do it How can I do that? any suggestions please?

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 23 Jul 2013
Edited: Andrei Bobrov on 23 Jul 2013
string = 'I am 24 Years old';
strrep(string,' ','');
for cell array
string = {'I am 24 Years old';'I am 24 Years old'}
strrep(string,' ','');
Jan on 23 Jul 2013
+1: STRREP operates on cell directly.

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 23 Jul 2013
s={'aa a aa'; 'a aaaa a'; 'a = aaaaa'}
out=cellfun(@(x) x(~ismember(x,' ')),s,'un',0)
  1 Comment
Jan on 23 Jul 2013
A simplification:
cellfun(@(x) x(x~=' ')), s, 'un', 0)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!