Convert cell array to numeric data

조회 수: 6 (최근 30일)
Jagannath Nanduri
Jagannath Nanduri 2017년 3월 9일
댓글: Alexandra Harkai 2017년 3월 9일
I have a large cell array of strings I am trying to convert to numeric data
> whos tt
Name Size Bytes Class Attributes
tt 8634370x1 6147671440 cell
tt(1)
ans =
{1x5 cell}
tt{1}
ans =
'2017' '058' '19' '24' '01.052261'
I am trying to convert this into a matrix of 8634370x5 using str2num or eval. I am lost in cell array indexing. Any help is greatly appreciated. Thanks.
Jaggu

답변 (1개)

Alexandra Harkai
Alexandra Harkai 2017년 3월 9일
cellfun(@str2num, tt)
will do the trick, cellfun applies str2num to every cell.
  댓글 수: 2
Stephen23
Stephen23 2017년 3월 9일
편집: Stephen23 2017년 3월 9일
+1 very nice. I think str2double would be more robust:
cellfun(@str2double, tt)
Alexandra Harkai
Alexandra Harkai 2017년 3월 9일
Cool, will keep str2double in mind!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by