フィルターのクリア

how to convert a column of cells into string?

3 ビュー (過去 30 日間)
Amr Hashem
Amr Hashem 2015 年 5 月 19 日
編集済み: per isakson 2015 年 5 月 20 日
when i try my code ( search for a word in a cells of column), i use :
% search for "battery" in column 52th
B=~cellfun('isempty',regexp(alldata(:,52),'BATTERY'))
i got an error : All cells must be strings.
B=~cellfun('isempty',regexp(alldata(:,52),'BATTERY'))
how i can solve this?
note: the column contain a texts but some cells is empty or contain NaN

採用された回答

per isakson
per isakson 2015 年 5 月 19 日
編集済み: per isakson 2015 年 5 月 19 日
NaN is double
>> class( nan )
ans =
double
replace Nan by '' (empty string)
>> alldata = {'abc', nan, 'def'}
alldata =
'abc' [NaN] 'def'
>> alldata{ not( cellfun( @ischar, alldata ) ) } = '';
>> alldata
alldata =
'abc' '' 'def'
  2 件のコメント
Amr Hashem
Amr Hashem 2015 年 5 月 19 日
how i can do a for loop on a column of cells which some are not string to make them string
per isakson
per isakson 2015 年 5 月 20 日
編集済み: per isakson 2015 年 5 月 20 日
>> alldata{ not( cellfun( @ischar, alldata ) ) } = '';
does that. Why use a loop?
any_string_value = 'abc';
for jj = 1 : length( alldata )
if not( ischar( alldata{jj} ) )
alldata{jj} = any_string_value;
end
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by