getvaropts
Get variable import options
Syntax
varOpts = getvaropts(opts,selection)
Description
Examples
获得进口选项变量
Access the variable import options object that controls the importing of a variable using thegetvaropts
function.
Create import options from a file. The options object is a collection of individual variable import options.
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 Range Properties: DataRange: 'A2' (Start Cell) VariableNamesRange: 'A1' RowNamesRange: '' VariableUnitsRange: '' VariableDescriptionsRange: '' To display a preview of the table, use preview
Get the variable import options object for the specified variable.
varOpts = getvaropts(opts,'Systolic')
varOpts = NumericVariableImportOptions with properties: Variable Properties: Name: 'Systolic' Type: 'double' FillValue: NaN TreatAsMissing: {} QuoteRule: 'remove' Prefixes: {} Suffixes: {} Numeric Options: ExponentCharacter: 'eEdD' DecimalSeparator: '.' ThousandsSeparator: '' TrimNonNumeric: 0
To modify the variable import options, see thesetvaropts
andsetvartype
function reference pages.
Input Arguments
opts
—File import options
保存权杖adsheetImportOptions
|DelimitedtextImportOptions
|FixedWidthImportOptions
File import options, specified as a保存权杖adsheetImportOptions
,DelimitedTextImportOptions
, or aFixedWidthImportOptions
object created by thedetectImportOptions
function. Theopts
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|cell array of character vector|array of indices
Selected variables, specified as a character vector, cell array of character vectors, or an array of numeric indices.
Variable names (or indices) must be a subset of the names contained in theVariableNames
property of theopts
object.
Example:'Height'
Example:{'Height','LastName'}
Example:[5 9]
Data Types:char
|cell
|uint64
Output Arguments
varOpts
— Type dependent options for selected variables
array of variable import options objects
Type dependent options for selected variables, returned as an array of variable import options objects. The array contains an object corresponding to each variable specified in theselection
argument. Depending on the data types of the variables, each object in the array is one of these types: numeric, text,logical
,datetime
, andcategorical
.
You can modify properties of the individual objects.
To modify the
Type
property, use thesetvartype
function.To modify other properties, use the
setvaropts
function.
See Also
Introduced in R2016b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
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.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)