options = detectImportOptions(filename)
options = detectImportOptions(filename, Name, Value)
| Parameter | Description |
|---|---|
| filename | a string: filename source. |
| Name, Value | JSON files only: FileType, TableSelector, TableNodeName, VariableSelectors, RowNamesSelector, VariableUnitsSelector, VariableDescriptionsSelector, RepeatedNodeRule, ParsingMode, AllowComments, AllowInfAndNaN, AllowTrailingCommas, MissingRule, ImportErrorRule and TextType (see readtable). |
| Parameter | Description |
|---|---|
| options | nelson.io.text.DelimitedTextImportOptions object. |
options = detectImportOptions(filename) identifies a table in a delimited text file and returns a nelson.io.text.DelimitedTextImportOptions object.
You can customize this object and use it withreadtable, readcell orreadmatrix to control how Nelson imports data as a table, cell array, or matrix.
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]
For a JSON file (.json extension or 'FileType', 'json'), detectImportOptions returns a nelson.io.json.JSONImportOptions object usable with readtable and readtimetable. Its TableSelector and VariableSelectors properties hold the detected JSON Pointers, VariableNames and VariableTypes the detected names and types.
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)
T = table([1; 2], ["a"; "b"], 'VariableNames', {'x', 'name'}); f = [tempdir, 'detect_json.json']; writetable(T, f); opts = detectImportOptions(f) opts.SelectedVariableNames = {'name'}; T2 = readtable(f, opts)
| Version | Description |
|---|---|
| 1.10.0 | initial version |
| 2.0.0 | JSON files: returns a JSONImportOptions object. |