.set 数据导入matlab,设置变量导入选项 - MATLAB setvaropts - MathWorks 中国
readtable 函数自动检测具有 0x 和 0b 前缀的十六进制和二进制数字。要导入这些数字不带前缀的形式,请使用导入选项对象。
为文件 hexAndBinary.txt 创建一个导入选项对象。其第三列包含十六进制数字,不带 0x 前缀。
opts = detectImportOptions('hexAndBinary.txt')
opts =
DelimitedTextImportOptions with properties:
Format Properties:
Delimiter: {','}
Whitespace: '\b\t '
LineEnding: {'\n' '\r' '\r\n'}
CommentStyle: {}
ConsecutiveDelimitersRule: 'split'
LeadingDelimitersRule: 'keep'
TrailingDelimitersRule: 'ignore'
EmptyLineRule: 'skip'
Encoding: 'UTF-8'
Replacement Properties:
MissingRule: 'fill'
ImportErrorRule: 'fill'
ExtraColumnsRule: 'addvars'
Variable Import Properties: Set types by name using setvartype
VariableNames: {'Var1', 'Var2', 'Var3' ... and 1 more}
VariableTypes: {'auto', 'auto', 'char' ... and 1 more}
SelectedVariableNames: {'Var1', 'Var2', 'Var3' ... and 1 more}
VariableOptions: Show all 4 VariableOptions
Access VariableOptions sub-properties using setvaropts/getvaropts
VariableNamingRule: 'modify'
Location Properties:
DataLines: [1 Inf]
VariableNamesLine: 0
RowNamesColumn: 0
VariableUnitsLine: 0
VariableDescriptionsLine: 0
To display a preview of the table, use preview
要指定第三列应作为十六进制值导入,即使缺失前缀也要导入,请使用 setvaropts 函数。将第三个变量的变量类型设置为 int32。将用于导入第三列的进制设置为 hex。
opts = setvaropts(opts,3,'NumberSystem','hex','Type','int32')
opts =
DelimitedTextImportOptions with properties:
Format Properties:
Delimiter: {','}
Whitespace: '\b\t '
LineEnding: {'\n' '\r' '\r\n'}
CommentStyle: {}
ConsecutiveDelimitersRule: 'split'
LeadingDelimitersRule: 'keep'
TrailingDelimitersRule: 'ignore'
EmptyLineRule: 'skip'
Encoding: 'UTF-8'
Replacement Properties:
MissingRule: 'fill'
ImportErrorRule: 'fill'
ExtraColumnsRule: 'addvars'
Variable Import Properties: Set types by name using setvartype
VariableNames: {'Var1', 'Var2', 'Var3' ... and 1 more}
VariableTypes: {'auto', 'auto', 'int32' ... and 1 more}
SelectedVariableNames: {'Var1', 'Var2', 'Var3' ... and 1 more}
VariableOptions: Show all 4 VariableOptions
Access VariableOptions sub-properties using setvaropts/getvaropts
VariableNamingRule: 'modify'
Location Properties:
DataLines: [1 Inf]
VariableNamesLine: 0
RowNamesColumn: 0
VariableUnitsLine: 0
VariableDescriptionsLine: 0
To display a preview of the table, use preview
读取文件并将前三列作为数值导入。readtable 函数自动检测包含第一列和第二列包含十六进制和二进制值。导入选项对象指定第三列也包含十六进制值。
T = readtable('hexAndBinary.txt',opts)
T=3×4 table
Var1 Var2 Var3 Var4
_____ ____ _____ ___________
255 255 51193 {'Device1'}
256 4 1471 {'Device2'}
43981 129 61455 {'Device3'}