Convert a Cell of Strings to a Double in Matlab

蓝咒 提交于 2019-12-02 01:38:41

str2double can be called directly on a cell array of strings:

>> X = str2double(A)
X =
    2.0000
    2.0000
       NaN
   23.0000
   23.6000

On an unrelated note, the notation used to define the cell array A can be simplified a bit:

>> A = {'2'; '2'; '****'; '23'; '23.6'}
A = 
    '2'
    '2'
    '****'
    '23'
    '23.6'

no need for all those curly brackets :)

Use the function str2double on each entry of the cell array like this:

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