Create import options based on file content
locates a table in a file and returns its import options. You can modify the options
object and use it with opts
= detectImportOptions(filename
)readtable
to control how MATLAB® imports tabular data. The type of the options returned depends on the
file extension. For example, the function returns a SpreadsheetImportOptions
object if
filename
is a spreadsheet file. However, the function returns
a DelimitedTextImportOptions
or FixedWidthImportOptions
object if
filename
is a text file.
locates a table in a file with the help of additional parameters specified by one or
more opts
= detectImportOptions(filename
,Name,Value
)Name,Value
pair arguments.
Detect import options for a spreadsheet file, specify the variables to import, and then read the data.
Create an import options object from a file.
opts = detectImportOptions('patients.xls')
opts = SpreadsheetImportOptions with properties: Sheet Properties: Sheet: '' Replacement Properties: MissingRule: 'fill' ImportErrorRule: 'fill' Variable Import Properties: Set types by name using setvartype VariableNames: {'LastName', 'Gender', 'Age' ... and 7 more} VariableTypes: {'char', 'char', 'double' ... and 7 more} SelectedVariableNames: {'LastName', 'Gender', 'Age' ... and 7 more} VariableOptions: Show all 10 VariableOptions Access VariableOptions sub-properties using setvaropts/getvaropts VariableNamingRule: 'modify' Range Properties: DataRange: 'A2' (Start Cell) VariableNamesRange: 'A1' RowNamesRange: '' VariableUnitsRange: '' VariableDescriptionsRange: '' To display a preview of the table, use preview
Modify the options object to specify which variables to import.
opts.SelectedVariableNames = {'Systolic','Diastolic'};
Use readtable
along with the options object to import the specified variables.
T = readtable('patients.xls',opts);
summary(T)
Variables: Systolic: 100x1 double Values: Min 109 Median 122 Max 138 Diastolic: 100x1 double Values: Min 68 Median 81.5 Max 99
Create import options, tailor the data types for multiple variables, and then read the data.
Create an import options object from a text file.
opts = detectImportOptions('airlinesmall.csv')
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: 'ISO-8859-1' Replacement Properties: MissingRule: 'fill' ImportErrorRule: 'fill' ExtraColumnsRule: 'addvars' Variable Import Properties: Set types by name using setvartype VariableNames: {'Year', 'Month', 'DayofMonth' ... and 26 more} VariableTypes: {'double', 'double', 'double' ... and 26 more} SelectedVariableNames: {'Year', 'Month', 'DayofMonth' ... and 26 more} VariableOptions: Show all 29 VariableOptions Access VariableOptions sub-properties using setvaropts/getvaropts VariableNamingRule: 'modify' Location Properties: DataLines: [2 Inf] VariableNamesLine: 1 RowNamesColumn: 0 VariableUnitsLine: 0 VariableDescriptionsLine: 0 To display a preview of the table, use preview
Examine the Type
property of the variables TaxiIn
and TaxiOut
.
getvaropts(opts,{'TaxiIn','TaxiOut'})
ans = 1x2 TextVariableImportOptions array with properties: Name Type FillValue TreatAsMissing QuoteRule Prefixes Suffixes EmptyFieldRule WhitespaceRule
Change the type of the variables TaxiIn
and TaxiOut
to double
.
opts = setvartype(opts,{'TaxiIn','TaxiOut'},'double');
Specify the subset of variables to import and examine.
opts.SelectedVariableNames = {'TaxiIn','TaxiOut'};
Use the readtable
function along with the options object to import the selected variables. Display a summary of the table.
T = readtable('airlinesmall.csv',opts);
summary(T)
Variables: TaxiIn: 123523x1 double Values: Min 0 Median 5 Max 1451 NumMissing 37383 TaxiOut: 123523x1 double Values: Min 0 Median 13 Max 755 NumMissing 37364
Import text data as a string data type by specifying import options.
Create an options object for the file.
opts = detectImportOptions('outages.csv');
Specify which variables to import using readtable
, and then show a summary. The data type of the selected variables is char
.
opts.SelectedVariableNames = {'Region','Cause'}; T = readtable('outages.csv',opts); summary(T)
Variables: Region: 1468x1 cell array of character vectors Cause: 1468x1 cell array of character vectors
Import text data as a string
data type, and then create import options by specifying the TextType
name-value pair.
opts = detectImportOptions('outages.csv','TextType','string');
Specify which variables to import using readtable
, and then show a summary. The data type of the selected variables is now string
.
opts.SelectedVariableNames = {'Region','Cause'}; T = readtable('outages.csv',opts); summary(T)
Variables: Region: 1468x1 string Cause: 1468x1 string
filename
— Name of file to readName of the file to read, specified as a character vector or string scalar.
Depending on the location of your file, filename
can
take on one of these forms.
Location | Form | ||||||||
---|---|---|---|---|---|---|---|---|---|
Current folder or folder on the MATLAB path | Specify the name of the file in
Example:
| ||||||||
File in a folder | If the file is not in the current folder or in
a folder on the MATLAB path, then specify the full or
relative path name in
Example:
Example:
| ||||||||
Remote Location | If the file is stored at a remote location,
then
Based on your remote location,
For more information, see Work with Remote Data. Example:
|
If filename
includes the file extension, then
detectImportOptions
determines the file format from
the extension. Otherwise, you must specify the 'FileType'
name-value pair to indicate the type of file.
The detectImportOptions
function supports these file
extensions: .txt
, .dat
,
.csv
, .xls
,
.xlsb
, .xlsm
,
.xlsx
, .xltm
,
.xltx
, and .ods
.
Note
File extensions .xlsb
and .ods
are only supported on platforms with Excel® for Windows®.
Data Types: char
| string
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
'FileType','spreadsheet'
'FileType'
— Type of file'spreadsheet'
| 'text'
| 'delimitedtext'
| 'fixedwidth'
Type of file, specified as the comma-separated pair consisting of
'FileType'
and one of these values.
Value | Import Options for File |
---|---|
'spreadsheet' | Return a |
'text' | Return a |
'delimitedtext' | Return a |
'fixedwidth' | Return a |
Use the 'FileType'
name-value pair argument when
filename
does not include the file extension, or
when the extension is not one of these:
.txt
, .dat
, or
.csv
for text files
.xls
, .xlsb
,
.xlsm
, .xlsx
,
.xltm
, .xltx
, or
.ods
for spreadsheet files
File extensions .xlsb
and .ods
are only supported on platforms with Excel for Windows.
Example: 'FileType','text'
Data Types: char
| string
'TextType'
— Type for imported text data 'char'
(default) | 'string'
Type for imported text data, specified as the comma-separated pair consisting of 'TextType'
and either 'char'
or 'string'
.
'char'
— Import text data into MATLAB as character vectors.
'string'
— Import text data into MATLAB as string arrays.
Example: 'TextType','char'
'DatetimeType'
— Type for imported date and time data'datetime'
(default) | 'text'
| 'exceldatenum'
(spreadsheet files only)Type for imported date and time data, specified as the comma-separated pair consisting of 'DatetimeType'
and one of these values: 'datetime'
, 'text'
, or 'exceldatenum'
. The value 'exceldatenum'
is applicable only for spreadsheet files, and is not valid for text files.
Value | Type for Imported Date and Time Data |
---|---|
'datetime' | MATLAB For more information, see |
'text' | If
|
'exceldatenum' | Excel serial date numbers A serial date number is a single number equal to the number of days from a given reference date. Excel serial date numbers use a different reference date than MATLAB serial date numbers. For more information on Excel dates, see |
Data Types: char
| string
'ExpectedNumVariables'
— Expected number of variablesExpected number of variables, specified as the comma-separated pair consisting of
'ExpectedNumVariables'
and a positive integer. If unspecified,
the importing function automatically detects the number of variables.
Data Types: single
| double
'Range'
— Portion of data to readPortion of the data to read from text or spreadsheet files, specified as the comma
separated pair consisting of 'Range'
and a character vector, string
scalar, or numeric vector in one of these forms.
Ways to specify Range | Description |
---|---|
Starting Cell
| Specify the starting cell for the data as a character vector or string scalar or a two element numeric vector.
Using the starting cell, the importing function automatically detects the extent of the data by beginning the import at the start cell and ending at the last empty row or footer range. Example:
|
Rectangular Range
| Specify the exact range to read using the rectangular range in one of these forms.
The importing function only reads the data contained in the specified range. Any empty fields within the specified range are imported as missing cells. |
Row Range or Column Range
| Specify the range by identifying the beginning and ending rows using Excel row numbers. Using the specified row range, the importing function automatically detects the column extent by reading from the first nonempty column to the end of the data, and creates one variable per column. Example:
Alternatively, specify the range by identifying the beginning and ending columns using Excel column letters or numbers. Using the specified column range, the import function automatically detects the row extent by reading from the first nonempty row to the end of the data or the footer range. The number of columns in
the specified range must match the number specified in the
Example:
|
Starting Row Number
| Specify the first row containing the data using the positive scalar row index. Using the specified row index, the importing function automatically detects the extent of the data by reading from the specified first row to the end of the data or the footer range. Example: |
Excel’s Named Range
| In Excel, you can create names to identify ranges in the
spreadsheet. For instance, you can select a rectangular portion of
the spreadsheet and call it Example:
|
Unspecified or Empty
| If unspecified, the importing function automatically detects the used range. Example:
Note: Used Range refers to the rectangular portion of the spreadsheet that actually contains data. The importing function automatically detects the used range by trimming any leading and trailing rows and columns that do not contain data. Text that is only white space is considered data and is captured within the used range. |
Data Types: char
| string
| double
'NumHeaderLines'
— Number of header linesNumber of header lines in the file, specified as the comma-separated pair consisting of 'NumHeaderLines'
and a positive integer. If unspecified, the importing function automatically detects the number of header lines in the file.
Example: 'NumHeaderLines',7
Data Types: single
| double
'ReadVariableNames'
— Read first row as variable namestrue
| false
Indicator for reading the first row as variable names, specified as the comma-separated pair consisting of 'ReadVariableNames'
and either true
or false
. If unspecified, readtable
automatically detects the presence of variable names.
Indicator | Description |
---|---|
| Use when the first row of the region to read contains the variable names for the table. |
| Use when the first row of the region to read contains data in the table. |
unspecified | When left unspecified, the importing function automatically detects true or false and proceeds accordingly. |
Data Types: logical
'VariableNamingRule'
— Flag to preserve variable names'modify'
(default) | 'preserve'
Flag to preserve variable names, specified as the comma-separated pair consisting of
VariableNamingRule
and either true
, or
false
.
'preserve'
— Preserve variable names that are not valid
MATLAB identifiers such as variable names that include spaces and
non-ASCII characters.
'modify'
— Convert invalid variable names (as
determined by the isvarname
function) to
valid MATLAB identifiers.
Starting in R2019b, variable names and row names can include any characters, including
spaces and non-ASCII characters. Also, they can start with any characters, not just
letters. Variable and row names do not have to be valid MATLAB identifiers (as determined by the isvarname
function). To preserve these variable names and row names, set
the value of VariableNamingRule
to
'preserve'
.
Data Types: char
| string
'ReadRowNames'
— Indicator for reading the first column as row namesfalse
(default) | true
Indicator for reading first column as row names, specified as the
comma-separated pair consisting of 'ReadRowNames'
and
either false
or
true
.
Indicator | Description |
---|---|
| Use when the first column of the region to read contains data, and not the row names for the table. |
| Use when the first column of the region to read contains the row names for the table. |
unspecified | When left unspecified, the importing function
assumes false . |
Data Types: logical
'MissingRule'
— Procedure to manage missing data'fill'
| 'error'
| 'omitrow'
| 'omitvar'
Procedure to manage missing data, specified as one of the values in this table.
Missing Rule | Behavior |
---|---|
'fill' | Replace missing data with the contents
of the The |
'error' | Stop importing and display an error message showing the missing record and field. |
'omitrow' | Omit rows that contain missing data. |
'omitvar' | Omit variables that contain missing data. |
Example: opts.MissingRule = 'omitrow';
Data Types: char
| string
'ImportErrorRule'
— Procedure to handle import errors'fill'
| 'error'
| 'omitrow'
| 'omitvar'
Procedure to handle import errors, specified as one of the values in this table.
Import Error Rule | Behavior |
---|---|
'fill' | Replace the data where the error occurred
with the contents of the The |
'error' | Stop importing and display an error message showing the error-causing record and field. |
'omitrow' | Omit rows where errors occur. |
'omitvar' | Omit variables where errors occur. |
Example: opts.ImportErrorRule = 'omitvar';
Data Types: char
| string
'Sheet'
— Sheet to read from''
empty character array (default) | character vector | string scalar | positive scalar integerSheet to read from, specified as an empty character array, a character vector or string scalar
containing the sheet name, or a positive scalar integer denoting the sheet
index. Based on the value specified for the Sheet
property, the import function behaves as described in the table.
Specification | Behavior |
---|---|
'' (default) | Import data from the first sheet. |
Name | Import data from the matching sheet name, regardless of order of sheets in the spreadsheet file. |
Integer | Import data from sheet in the position denoted by the integer, regardless of the sheet names in the spreadsheet file. |
Data Types: char
| string
| single
| double
'DataRange'
— Location of dataLocation of data to be imported, specified as a character vector, string scalar, cell array of character vectors, string array, positive scalar integer or an N
-by-2
array of positive scalar integers. Specify DataRange
using one of these forms.
Specified by | Behavior |
---|---|
Starting Cell or Starting Row | Specify the starting cell for the data, using Excel Using the starting cell, the importing function automatically detects the extent of the data, by beginning the import at the start cell and ending at the last empty row or footer range. Alternatively, specify the first row containing the data using the positive scalar row index. Using the specified row index, the importing function automatically detects the extent of the data by reading from the specified first row to the end of the data or the footer range. Example: |
Rectangular Range | Specify the exact range to read using the rectangular range form, where The importing function only reads the data contained in the specified range. Any empty fields within the specified range are imported as missing cells. The number of columns must match the number specified in the Example: |
Row Range or Column Range | Specify the range by identifying the beginning and ending rows using Excel row numbers. Using the specified row range, the importing function automatically detects the column extent by reading from the first nonempty column to the end of the data, and creates one variable per column. Example: Alternatively, specify the range by identifying the beginning and ending columns using Excel column letters or numbers. Using the specified column range, the import function automatically detects the row extent by reading from the first nonempty row to the end of the data or the footer range. The number of columns in the specified range must match the number specified in the Example: |
Multiple Row Ranges | Specify multiple row ranges to read with an A valid array of multiple row ranges must:
Use of Example: |
Unspecified or Empty | Do not fetch any data. Example: |
Data Types: char
| string
| cell
| single
| double
'RowNamesRange'
— Location of row names''
empty character arrayLocation of row names, specified as a character vector, string scalar, positive scalar integer, or an empty character array. Specify RowNamesRange
as one of the values in this table.
Specified by | Behavior |
---|---|
| Specify the starting cell for the data, using Excel The importing function identifies a name for each variable in the data. Example: |
Rectangular Range | Specify the exact range to read using the rectangular range form, where The number of rows contained in Example: |
Row Range | Specify range by identifying the beginning and ending rows using Excel row numbers. Row names must be in a single column. Example: |
Number Index | Specify the column containing the row names using a positive scalar column index. Example: |
Unspecified or Empty | Indicate that there are no row names. Example: |
Data Types: char
| single
| double
'VariableNamesRange'
— Location of variable names''
empty character arrayLocation of variable names, specified as a character vector, string scalar, positive scalar integer, or an empty character array. Specify VariableNamesRange
as one of the values in this table.
Specified by | Behavior |
---|---|
| Specify the starting cell for the data, using Excel The importing function reads a name for each variable in the data. Example: |
Rectangular Range | Specify the exact range to read using the rectangular range form, where The number of columns must match the number specified in the Example: |
Row Range | Specify range by identifying the beginning and ending rows using Excel row numbers. Must be a single row. Example: |
Number Index | Specify the row containing the variable names using a positive scalar row index. Example: |
Unspecified or Empty | Indicate that there are no variable names. Example: |
Data Types: char
| single
| double
'VariableUnitsRange'
— Location of variable units''
empty character arrayLocation of variable units, specified as a character vector, string scalar, positive scalar integer, or an empty character array. Specify VariableUnitsRange
as one of the values in this table.
Specified by | Behavior |
---|---|
| Specify the starting cell for the data, using Excel The importing function reads a unit for each variable in the data. Example: |
Rectangular Range | Specify the exact range to read using the rectangular range form, where The number of columns must match the number specified in the Example: |
Row Range | Specify range by identifying the beginning and ending rows using Excel row numbers. Must be a single row. Example: |
Number Index | Specify the row containing the data units using a positive scalar row index. Example: |
Unspecified or Empty | Indicate that there are no variable units. Example: |
Data Types: char
| string
| single
| double
'VariableDescriptionsRange'
— Location of variable descriptions''
empty character arrayLocation of variable descriptions, specified as a character vector, string scalar, positive scalar integer, or an empty character array. Specify VariableDescriptionRange
as one of the values in this table.
Specified by | Behavior |
---|---|
| Specify the starting cell for the data, using Excel The importing function reads a description for each variable in the data. Example: |
Rectangular Range | Specify the exact range to read using the rectangular range form, where The number of columns must match the number specified in the Example: |
Row Range | Specify range by identifying the beginning and ending rows using Excel row numbers. Must be a single row. Example: |
Number Index | Specify the row containing the descriptions using a positive scalar row index. Example: |
Unspecified or Empty | Indicate that there are no variable descriptions. Example: |
Data Types: char
| string
| single
| double
'Delimiter'
— Field delimiter charactersField delimiter characters in a delimited text file, specified as a character vector, string scalar, cell array of character vectors, or string array.
Example: 'Delimiter','|'
Example: 'Delimiter',{';','*'}
Data Types: char
| string
| cell
'LeadingDelimitersRule'
— Procedure to manage leading delimiters'keep'
| 'ignore'
| 'error'
Procedure to manage leading delimiters in a delimited text file, specified as one of the values in this table.
Leading Delimiters Rule | Behavior |
---|---|
'keep' | Keep the delimiter. |
'ignore' | Ignore the delimiter. |
'error' | Return an error and abort the import operation. |
'TrailingDelimitersRule'
— Procedure to manage trailing delimiters'keep'
| 'ignore'
| 'error'
Procedure to manage trailing delimiters in a delimited text file, specified as one of the values in this table.
Leading Delimiters Rule | Behavior |
---|---|
'keep' | Keep the delimiter. |
'ignore' | Ignore the delimiter. |
'error' | Return an error and abort the import operation. |
'ConsecutiveDelimitersRule'
— Procedure to handle consecutive delimiters'split'
| 'join'
| 'error'
Procedure to handle consecutive delimiters in a delimited text file, specified as one of the values in this table.
Consecutive Delimiters Rule | Behavior |
---|---|
'split' | Split the consecutive delimiters into multiple fields. |
'join' | Join the delimiters into one delimiter. |
'error' | Return an error and abort the import operation. |
Data Types: char
| string
'VariableWidths'
— Field widths of variablesField widths of variables in a fixed-width text file, specified as a vector of positive
integer values. Each positive integer in the vector corresponds to the number of
characters in a field that makes up the variable. The VariableWidths
property contains an entry corresponding to each variable specified in the
VariableNames
property.
'Whitespace'
— Characters to treat as white spaceCharacters to treat as white space, specified as a character vector or string scalar containing one or more characters.
Example: 'Whitespace',' _'
Example: 'Whitespace','?!.,'
'LineEnding'
— End-of-line characters{'\n','\r','\r\n'}
(default) | character vector | string scalar | cell array of character vectors | string arrayEnd-of-line characters, specified as a character vector, string scalar, cell array of character vectors, or string array.
Example: 'LineEnding','\n'
Example: 'LineEnding','\r\n'
Example: 'LineEnding',{'\b',':'}
Data Types: char
| string
| cell
'Encoding'
— Character encoding scheme''
| 'UTF-8'
| 'system'
| 'ISO-8859-1'
| 'windows-1251'
| 'windows-1252'
| ...Character encoding scheme associated with the file, specified as the comma-separated
pair consisting of 'Encoding'
and 'system'
or a
standard character encoding scheme name.
When you do not specify any encoding, the function uses automatic character set detection to determine the encoding when reading the file.
Example: 'Encoding','system'
uses the system default
encoding.
Data Types: char
| string
'CommentStyle'
— Style of commentsStyle of comments, specified as a character vector, string scalar, cell array of character vectors, or string array.
For example, to ignore the text following a percent sign on the same line, specify
CommentStyle
as '%'
.
Example: 'CommentStyle',{'/*'}
Data Types: char
| string
| cell
'DurationType'
— Output data type of duration data'duration'
(default) | 'text'
Output data type of duration data from text files, specified as the comma-separated pair consisting of 'DurationType'
and either 'duration'
or 'text'
.
Value | Type for Imported Duration Data |
---|---|
'duration' | MATLAB For more information, see |
'text' | If
|
Data Types: char
| string
'ExtraColumnsRule'
— Procedure to handle extra columns'addvars'
| 'ignore'
| 'wrap'
| 'error'
Procedure to handle extra columns in the data, specified as one of the values in this table.
Extra Columns Rule | Behavior |
---|---|
'addvars' | To import extra columns, create new
variables. If there are NOTE:
The extra columns are imported as text with data type |
'ignore' | Ignore the extra columns of data. |
'wrap' | Wrap the extra columns of data to new records. This action does not change the number of variables. |
'error' | Display an error message and abort the import operation. |
Data Types: char
| string
'TreatAsMissing'
— Text to interpret as missing dataText to interpret as missing data, specified as a character vector, string scalar, cell array of character vectors, or string array.
When the importing function finds missing instances, it uses the
specification in the MissingRule
property to
determine the appropriate action.
Example: 'TreatAsMissing',{'NA','TBD'}
instructs the
importing function to treat any occurrence of NA
or
TBD
as a missing fields.
Data Types: char
| string
| cell
'DateLocale'
— Locale for reading datesLocale for reading dates, specified as the comma-separated pair consisting of
'DateLocale'
and a character vector or a string scalar of the
form
, where:xx
_YY
YY
is an uppercase ISO 3166-1 alpha-2 code
indicating a country.
xx
is a lowercase ISO 639-1 two-letter code
indicating a language.
For a list of common values for the locale, see the Locale
name-value pair argument for the datetime
function.
When using the %D
format specifier to read text as
datetime
values, use DateLocale
to specify the
locale in which the importing function should interpret month and day-of-week names and
abbreviations.
If you specify the DateLocale
argument in addition to
opts
the import options, then the importing function uses the
specified value for the DateLocale
argument, overriding the locale
defined in the import options.
Example: 'DateLocale','ja_JP'
'ThousandsSeparator'
— Characters that indicate the thousands groupingCharacters that indicate the thousands grouping in numeric variables,
specified as a character vector or string scalar. The thousands grouping
characters act as visual separators, grouping the number at every three
place values. The importing function uses the characters in the
ThousandsSeparator
property to interpret the
numbers being imported.
Data Types: char
| string
'DecimalSeparator'
— Characters indicating decimal separatorCharacters indicating the decimal separator in numeric variables,
specified as a character vector or string scalar. The importing function
uses the DecimalSeparator
property to distinguish the
integer part of a number from the decimal part.
When converting to integer data types, numbers with a decimal part are rounded to the nearest integer.
Data Types: char
| string
'TrimNonNumeric'
— Remove nonnumeric charactersfalse
(default) | true
Remove nonnumeric characters from a numeric variable, specified as a
logical true
or false
.
Data Types: logical
'HexType'
— Output data type of hexadecimal data'auto'
(default) | 'text'
| 'int8'
| 'int16'
| ...Output data type of hexadecimal data, specified as the comma-separated pair consisting of 'HexType'
and one of the values listed in the table.
The input file represents hexadecimal values as text, using either 0x
or
0X
as a prefix and the characters
0
-9
,
a
-f
, and A
-F
as digits. (Uppercase and lowercase letters represent the same digits—for example,
'0xf'
and '0xF'
both represent
15
.)
The importing function converts the hexadecimal values to the data type specified by
the value of 'HexType'
.
Value of | Data Type of Output Table Variables |
---|---|
| data type detected automatically |
| unaltered input text |
| 8-bit integer, signed |
| 16-bit integer, signed |
| 32-bit integer, signed |
| 64-bit integer, signed |
| 8-bit integer, unsigned |
| 16-bit integer, unsigned |
| 32-bit integer, unsigned |
| 64-bit integer, unsigned |
Example: 'HexType','uint16'
converts text representing hexadecimal values (such as '0xFF'
) to unsigned 16-bit integers (such as 255
) in the output table.
Data Types: char
| string
'BinaryType'
— Output data type of binary data'auto'
(default) | 'text'
| 'int8'
| 'int16'
| ...Output data type of binary data, specified as the comma-separated pair consisting of
'BinaryType'
and one of the values listed in the table.
The input file represents binary values as text, using either 0b
or
0B
as a prefix and the characters 0
and
1
as digits.
The importing function converts the binary values to the data type specified by the
value of 'BinaryType'
.
Value of | Data Type of Output Table Variables |
---|---|
| data type detected automatically |
| unaltered input text |
| 8-bit integer, signed |
| 16-bit integer, signed |
| 32-bit integer, signed |
| 64-bit integer, signed |
| 8-bit integer, unsigned |
| 16-bit integer, unsigned |
| 32-bit integer, unsigned |
| 64-bit integer, unsigned |
Example: 'BinaryType','uint16'
converts text representing binary
values (such as '0b11111111'
) to unsigned 16-bit integers (such as
255
) in the output table.
Data Types: char
| string
opts
— Import options for fileSpreadsheetImportOptions
| DelimitedtextImportOptions
| FixedWidthImportOptions
Import options for the specified file, returned as a SpreadsheetImportOptions
object
or a DelimitedTextImportOptions
object. The type
of options object depends on the type of file specified. For text
files (.txt
, .dat
, or .csv
),
the detectImportOptions
function returns a DelimitedTextImportOptions
or FixedWidthImportOptions
object.
For spreadsheet files (.xls
, .xlsb
, .xlsm
, .xlsx
, .xltm
, .xltx
,
or .ods
), the detectImportOptions
function
returns a SpreadsheetImportOptions
object.
Updating Property Values After Creating the Import
Options Object: Use of dot notation to update the properties of
the import options object created by detecImportOptions
is
not recommended. Setting properties using dot notation does not lead to a
re-detection of all the import options for the file. Therefore, to update and
re-detect all the properties, you must specify the new values by using
name-value pairs. For example, update the value for the
ConsecutiveDelimitersRule
property and re-detect the
import options as follows.
opts = detectImportOptions(__,'ConsecutiveDelimitersRule','join')
You have a modified version of this example. Do you want to open this example with your edits?