Convert cell array to numeric data

22 Ansichten (letzte 30 Tage)
Jagannath Nanduri
Jagannath Nanduri am 9 Mär. 2017
Kommentiert: Alexandra Harkai am 9 Mär. 2017
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

Antworten (1)

Alexandra Harkai
Alexandra Harkai am 9 Mär. 2017
cellfun(@str2num, tt)
will do the trick, cellfun applies str2num to every cell.
  2 Kommentare
Stephen23
Stephen23 am 9 Mär. 2017
Bearbeitet: Stephen23 am 9 Mär. 2017
+1 very nice. I think str2double would be more robust:
cellfun(@str2double, tt)
Alexandra Harkai
Alexandra Harkai am 9 Mär. 2017
Cool, will keep str2double in mind!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by