setVartype
设置可变数据类型
句法
opts = setVartype(opts,type)
选择= setVartype(选择,,,,选择,,,,类型)
描述
例子
设置多个变量的数据类型
利用检测iMportoptions
至create import options, set multiple variable data types, and then read the data using可读取
。
创建一个选项对象。
选择= detectImportOptions('患者.xls');
检查变量的当前(检测到的)数据类型。
disp([[opts.variablenames'opts.variabletypes'])
'lastname'char''性别'char'''''double'''位置'char'''高度''double''重量''double''smokical''逻辑''''''''''''''double''double''double'自selfsessedHealthStatus''char'
根据您的导入需求,更改多个变量的数据类型。
opts = setVartype(opts,{'姓',,,,'性别',,,,'Location',,,,...“吸烟者”,,,,“自我评估”},,'细绳');opts = setVartype(opts,{'年龄',,,,'Height',,,,'重量',,,,...“收缩期”,,,,``舒张''},,'单身的');
检查变量的更新数据类型。
disp([[opts.variablenames'opts.variabletypes'])
'姓''细绳''性别''细绳''年龄''单身的''Location' 'string' 'Height' 'single' 'Weight' 'single' 'Smoker' 'string' 'Systolic' 'single' 'Diastolic' 'single' 'SelfAssessedHealthStatus' 'string'
使用其更新类型的变量使用可读取
。
t =可读取('患者.xls',选择);
输入参数
选择
-文件导入选项
SpreadsheetImportOptions
|DelelimitedTextimportoptions
|FixedWidthImportOptions
文件导入选项,,,,specified as aSpreadsheetImportOptions
,,,,DelelimitedTextimportoptions
, 或者aFixedWidthImportOptions
由检测iMportoptions
功能。这选择
对象包含控制数据导入过程的属性,例如可变属性,数据位置属性,替换规则等。
选择
-选定的变量
角色向量|细胞array of character vector|array of indices
选定的变量,指定为字符向量,字符向量的单元格数或数字索引数组。
可变名称(或索引)必须是该名称中包含的名称的子集变型
property of the选择
object.
例子:'Height'
例子:{'height','lastname'}
例子:[5 9]
数据类型:char
|细胞
|Uint64
类型
-可变数据类型
角色向量|字符向量的单元格数
可变数据类型,指定为字符向量或包含有效数据类型名称的字符向量的单元格数组。这类型
参数指定导入变量时要使用的数据类型。使用此处列出的数据类型之一导入变量。
Data | MATLAB®Data Type |
---|---|
文本 |
|
数字 |
未定义的浮点数
相同的转换过程适用于所有整数数据类型: |
逻辑 |
|
Date and time |
|
分类 |
|
例子:选择= setVartype(选择,,,,'Height','double')
changes the data type of the variableHeight
至双倍的
。
例子:opts = setVartype(opts,{'重量',,,,'姓'},,{'single','string'})
changes the data type of the variable重量
至单身的
and variable姓
至细绳
。
数据类型:细胞
|单身的
|双倍的
|int8
|int16
|INT32
|INT64
|UINT8
|UINT16
|UINT32
|Uint64
|逻辑
|char
|分类
|datetime
在R2016b中引入
matlab命令
您单击了与此MATLAB命令相对应的链接:
通过在MATLAB命令窗口中输入该命令。Web浏览器不支持MATLAB命令。金宝app
您还可以从以下列表中选择一个网站:
如何获得最佳网站性能
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
美洲
- América Latina(Español)
- 加拿大(英语)
- 美国(英语)