在Matlab中将字符串转换为双精度 [英] Convert a Cell of Strings to a Double in Matlab

查看:1163
本文介绍了在Matlab中将字符串转换为双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何转换单元格如下:

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

A =

'2'
'2'
'****'
'23'
'23 .6'
/ pre>

按以下方式进行双倍

  A = 

2.0000
2.0000
NaN
23.0000
23.6000


解决方案

str2double 可以直接在单元格数组上调用:

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




在一个无关的笔记中,用于定义单元格数组的符号 A 可以简化一下:

 >> A = {'2'; 2’ ; ****; 23’ ; '23 .6'} 
A =
'2'
'2'
'****'
'23'
'23 .6'

不需要所有这些大括号:)


How do i convert a Cell as the following:

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

A = 

    '2'
    '2'
    '****'
    '23'
    '23.6'  

To a double as the Following

A =

    2.0000
    2.0000
       NaN
   23.0000
   23.6000

解决方案

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 :)

这篇关于在Matlab中将字符串转换为双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆