Convert cell to double

user1532230 picture user1532230 · Jul 17, 2012 · Viewed 30.4k times · Source
>> C = [{1} {2} ; {'@CF'} {2}] 
C = 

[  1]    [2]
'@CF'    [2]


>> whos C
  Name      Size            Bytes  Class    Attributes

  C         2x2               478  cell  

How can I convert C into double so that:

>> C
C = 
1    2
NaN  2

I've tried str2double(C). It returns:

   NaN   NaN
   NaN   NaN

Answer

tmpearce picture tmpearce · Jul 17, 2012
C = [{1} {2} ; {'@CF'} {2}]

C = 

    [  1]    [2]
    '@CF'    [2]

D = cellfun(@isnumeric,C);
C(~D)={nan}

C = 

    [  1]    [2]
    [NaN]    [2]

cell2mat(C)

ans =

     1     2
   NaN     2