opts = setvartype(opts,type)
updates all the variables in the opts object based on the
specified type. type must be a character vector or a cell array
of character vector of valid data type names.
File import options, specified as a SpreadsheetImportOptions, DelimitedTextImportOptions,
or a FixedWidthImportOptions object created by
the detectImportOptions function.
The opts object contains properties that control
the data import process, such as variable properties, data location
properties, replacement rules, and others.
selection — Selected variables character vector | string scalar | cell array of character vector | string array | array of indices | logical array
Selected variables, specified as a character vector, string scalar, cell
array of character vectors, string array, array of numeric indices, or a
logical array.
Variable names (or indices) must be a subset of the names contained in the
VariableNames property of the opts
object.
type — Variable data type character vector | string scalar | cell array of character vectors | string array
Variable data type, specified as a character vector, string scalar, cell
array of character vectors, or string array containing valid data type
names. The type argument designates the data types to use
when importing the variable. Import the variables using one of the data
types listed here.
Undefined
floating-point numbers NaN,
-Inf, +Inf
are only valid for single and
double data types. Therefore,
when you change the type of floating-point data to
an integer, the importing function converts the
undefined floating-point numbers. For example, when
converting to the 'uint8' data type:
NaN is converted to
0.
-Inf is converted to
intmin('int8').
+Inf is converted to
intmax('int8').
The same conversion process applies
to all the integer data types:
int8, int16,
int16,
int32, int64,
uint8,
uint16,
uint32, or
uint64.
Logical
'logical'
Date and time
'datetime'
Duration
'duration'
Categorical
'categorical'
Example: opts = setvartype(opts,'Height','double')
changes the data type of the variable Height to
double.
Example: opts =
setvartype(opts,{'Weight','LastName'},{'single','string'})
changes the data type of the variable Weight to
single and variable LastName to
string.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.