FUNCTION REFERENCE

setvartype

Set the types of variables in import options.

Set the types of variables in import options.

Syntax

opts = setvartype(opts, type)

Syntax

opts = setvartype(opts, selection, type)

Returns a copy of opts in which the selected variables (all of them without a selection) have the given type: 'double', 'single', 'int8' to 'uint64', 'logical', 'char', 'string', 'datetime', 'duration' or 'categorical'. The selection is a name, a cell array of names, a string array or variable indices; type is one name, or a cell array with one name per selected variable. A changed type keeps the variable's name, TreatAsMissing, QuoteRule, Prefixes, Suffixes and EmptyFieldRule; the other variable options (FillValue included) take the new type's defaults.

Example

writetable(table([1; 2], [3; 4], 'VariableNames', {'a', 'b'}), 'ab.csv'); opts = setvartype(detectImportOptions('ab.csv'), 'b', 'string'); T = readtable('ab.csv', opts); class(T.b)   % 'string'

Differences from MATLAB: none known in these forms.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.