Convert cell to double

>> C = [{1} {2} ; {'@CF'} {2}] C = [ 1] [2] '@CF' [2] >> whos C Name Size Bytes Class Attributes C 2x2 478 cell 

How to convert C to double so that:

 >> C C = 1 2 NaN 2 

I tried str2double(C) . It returns:

  NaN NaN NaN NaN 
+6
source share
3 answers

Find numerical values isnumeric , query cellfun . Use this with logical indexing to extract numeric values:

 C = [{1} {2} ; {'@CF'} {2}]; isnum = cellfun(@isnumeric,C); result = NaN(size(C)); result(isnum) = [C{isnum}]; 
+5
source
 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 
+10
source

Well, you have mixed data types here, so there is no very direct way to do this.

The easiest way I can think of if you know exactly where you want it - just use cell2mat

IE: cell2mat(C(1,1)) returns 1 as double.

0
source

Source: https://habr.com/ru/post/920700/


All Articles