how to convert cell array to numeric array?

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
Stephen23 2021 年 12 月 3 日
What numeric value do you expect to get from a character vector like 'fh8453655' ?
Suresh R
Suresh R 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
Stephen23
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
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
Mathieu NOE 2021 年 12 月 3 日

0 投票

maybe this ?
>> a = {'fh8453655'}
>> beginStr = regexp(a, '\d+', 'match');
>> beginNumbers = cellfun(@(x) str2double(x{1}), beginStr)
beginNumbers =
8453655

1 件のコメント

Stephen23
Stephen23 2021 年 12 月 3 日
Simpler, but equally fragile:
a = {'fh8453655'}
a = 1×1 cell array
{'fh8453655'}
b = str2double(regexprep(a,'\D+',''))
b = 8453655
b = str2double(regexp(a,'\d+','match','once'))
b = 8453655

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

カテゴリ

質問済み:

2021 年 12 月 3 日

コメント済み:

2021 年 12 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by