detectImportOptions

Create import options based on file content.

Syntax

  • options = detectImportOptions(filename)

Input argument

  • filename - a string: filename source.

Output argument

  • options - DelimitedTextImportOptions object.

Description

options = detectImportOptions(filename) identifies a table in a file and returns an import options object.

You can customize this object and use it with readtable, readcell or readmatrix to control how Nelson imports data as a table, cell array, or matrix.

The type of the returned options object depends on the file's extension.

Properties:

Delimiter: Field delimiter characters. example: {','}

LineEnding: End-of-line characters. example: {'\r\n'}

CommentStyle: Style of comments. example: {'#'}

EmptyLineRule: Procedure to handle empty lines. example: 'skip'

VariableNamesLine: Variable names location. example: 1

VariableNames: Variable names. example: {'Names' 'Age' 'Height' 'Weight'}

RowNamesColumn: Row names location. example: 0

DataLines: Data location, [l1 l2] Indicate the range of lines containing the data. l1 refers to the first line with data, while l2 refers to the last line. example: [2 Inf]

Example

Names = {'John'; 'Alice'; 'Bob'; 'Diana'};
Age = [28; 34; 22; 30];
Height = [175; 160; 180; 165];
Weight = [70; 55; 80; 60];
T = table(Names, Age, Height, Weight);
writetable(T, [tempdir,'readcell_1.csv'])
options = detectImportOptions([tempdir,'readcell_1.csv'])
C1 = readcell([tempdir,'readcell_1.csv'], options)
options.DataLines = [1 Inf]
C2 = readcell([tempdir,'readcell_1.csv'], options)

See also

readcell, readtable, readmatrix.

History

Version
Description

1.10.0

initial version

Author

Allan CORNET

Last updated