Mixed data types cell to string

7 ビュー (過去 30 日間)
Daniel Kin
Daniel Kin 2013 年 4 月 10 日
Using xlsread I read the a spreadsheet
[ndata, text, alldata] = xlsread(filename);
One cloumn of alldata is a mixed data types as shown below (strings and integers). As I wish to use it for further analysis, is it possible to convert all this cell to be strings?
Thanks.
Cell output:
'NoGroup'
'NoGroup'
'NoGroup'
[1]
[1]
[1]
[2]
[2]
[2]
[2]
[2]
[2]
'Group3'
'Group3'
'Group3'

採用された回答

Jan
Jan 2013 年 4 月 10 日
C = {'NoGroup', 1; 2; 'Group3'};
for iC = 1:numel(C)
if ~ischar(C{iC});
C{iC} = num2str(C{iC});
end
end
There are alternatives like cellfun('isclass', C, 'char') or sprintf('%g', C[iC}).
  1 件のコメント
Daniel Kin
Daniel Kin 2013 年 4 月 10 日
Thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by