white space in cell array

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 日

3 投票

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 件のコメント

Jack_111
Jack_111 2013 年 7 月 23 日
My problem is, in applying it to a my cell array
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 日

0 投票

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)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by