cell array conversion to numeric

My cell array looks somewhat like this:
a = {'xxx' , 'xxx' , '24' , '63' , 'ggg' , 'ggg'}
Note: the numbers are also formatted as strings.
Is there a one-line operation (without loops) to convert the 'xxx' and 'ggg' to NaN, and the numbers in strings to numeric so that a becomes numeric array?

回答 (1 件)

Image Analyst
Image Analyst 2014 年 8 月 2 日

0 投票

Use str2double():
a = {'xxx' , 'xxx' , '24' , '63' , 'ggg' , 'ggg'}
out = str2double([a])
whos out
In the command window:
a =
'xxx' 'xxx' '24' '63' 'ggg' 'ggg'
out =
NaN NaN 24 63 NaN NaN
Name Size Bytes Class Attributes
out 1x6 48 double

カテゴリ

ヘルプ センター および File ExchangeData Types についてさらに検索

タグ

質問済み:

2014 年 8 月 2 日

回答済み:

2014 年 8 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by