This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Get variable import options


varOpts = getvaropts(opts,selection)



varOpts = getvaropts(opts,selection) returns the variable import options for the variables specified in selection.


collapse all

Access the variable import options object that controls the importing of a variable using the getvaropts 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: ''

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'

   Numeric Options:
     ExponentCharacter: 'eEdD'
      DecimalSeparator: '.'
    ThousandsSeparator: ''

To modify the variable import options, see the setvaropts and setvartype function reference pages.

Input Arguments

collapse all

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.

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 the VariableNames property of the opts object.

Example: 'Height'

Example: {'Height','LastName'}

Example: [5 9]

Data Types: char | cell | uint64

Output Arguments

collapse all

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 the selection argument. Depending on the data types of the variables, each object in the array is one of these types: numeric, text, logical, datetime, and categorical.

You can modify properties of the individual objects.

  • To modify the Type property, use the setvartype function.

  • To modify other properties, use the setvaropts function.

Introduced in R2016b

Was this topic helpful?