how to convert cell array to numeric array?
4 次查看(过去 30 天)
显示 更早的评论
how to convert cell array of size (4514,1) to numeric array where each cell has values like 'fh8453655' and some cells are nan.
4 个评论
Stephen23
2021-12-3
"numeric in the sense i want to convert this cell array to a array where my array type is double with same data"
Okay. Please show us the exact numeric value that you expect to get for the character vector 'fh8453655' .
Jan
2021-12-3
In other words: fh8453655 is not a number. It is not clear, what you expect as output. Perhaps 8453655?
回答(1 个)
Mathieu NOE
2021-12-3
maybe this ?
>> a = {'fh8453655'}
>> beginStr = regexp(a, '\d+', 'match');
>> beginNumbers = cellfun(@(x) str2double(x{1}), beginStr)
beginNumbers =
8453655
1 个评论
Stephen23
2021-12-3
Simpler, but equally fragile:
a = {'fh8453655'}
b = str2double(regexprep(a,'\D+',''))
b = str2double(regexp(a,'\d+','match','once'))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!