how to convert cell array to numeric array?
조회 수: 1 (최근 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!