Convert cell to double

痞子三分冷 提交于 2019-12-04 03:58:37

Find the non numeric values with isnumeric, queried by cellfun. Use that with logical indexing to extract the numeric values:

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

Well, you have mixed data types here so there isn't a very straight forward way to do it.

The easiest way I can think of, if you know where the data is you want, is to simply use cell2mat

IE: cell2mat(C(1,1)) would return 1 as a double.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!