detectImportOptions — Inspect text or spreadsheet data and create import options for tabular readers.
opts = detectImportOptions(filename) samples a delimited text or spreadsheet file and returns an editable scalar struct accepted by readtable and, for numeric text imports, readmatrix.
Syntax
opts = detectImportOptions(filename)
opts = detectImportOptions(filename, nameValuePairs...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
filename | StringScalar | Yes | — | Text or spreadsheet file path to inspect. |
nameValuePairs | Any | Variadic | — | Detection overrides such as Delimiter, Range, Sheet, Encoding, or TextType. |
Returns
| Name | Type | Description |
|---|---|---|
opts | Any | Detected import options struct accepted by readtable/readmatrix. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:table:InvalidArgument | Arguments or table metadata are invalid. | table: invalid argument |
RunMat:table:InvalidIndex | Table indexing is invalid. | table: invalid index |
RunMat:table:InvalidVariable | A table variable name or value is invalid. | table: invalid variable |
RunMat:readtable:IOError | readtable cannot open or read the requested file. | readtable: file read failed |
RunMat:readtable:UnsupportedFileType | readtable receives a file type outside the text or spreadsheet import backends. | readtable: unsupported file type |
How detectImportOptions works
- Detects text delimiters from comma, tab, semicolon, pipe, and whitespace-separated records unless
Delimiteris supplied. - Infers variable names from a non-data header row and sets
NumHeaderLinesso readers import only data rows. - Infers
VariableTypesasdouble,logical,datetime, or text (string/char) using the same token rules asreadtable. - Honors the implemented text/spreadsheet override subset, including
FileType,Delimiter,NumHeaderLines,Range,DataRange,Sheet,ExpectedNumVariables,VariableNamesLine,VariableNames,VariableTypes,ReadVariableNames,ReadRowNames,TreatAsMissing,VariableNamingRule,TextType,DatetimeType,EmptyLineRule, andEncoding. - Integer
Range,DataRange,Sheet,ExpectedNumVariables, andVariableNamesLinecontrols are parsed exactly from all eight integer classes.ExpectedNumVariablesandSheetmust be positive; boolean controls accept only logical values or exact numeric zero/one. - Numeric
DataRangecurrently supports a positive scalar start row or one 1-by-2 increasing row interval. Textual cell references are supported for detected-option replay; multiple numeric Nx2 intervals remain a recorded general gap. - Typed-integer
NumHeaderLinesis a RunMat-only extension. Compatibility mode rejects it before provider or file access; scalar single and double remain public inputs. - For spreadsheet files, uses the same sheet/range reader as
readtableand emits spreadsheet-compatible option fields. - The returned struct intentionally contains fields understood by current RunMat readers. Concrete MATLAB import-options classes and JSON, XML, Word, HTML, and archive option families remain recorded general gaps.
Does RunMat run detectImportOptions on the GPU?
No acceleration provider hooks are used. Resident arguments are rejected without a download.
GPU memory and residency
detectImportOptions performs file inspection on the host and returns host metadata. It does not create GPU-resident arrays.
Examples
Detect And Reuse CSV Import Options
opts = detectImportOptions("measurements.csv");
T = readtable("measurements.csv", opts);Override Detection Settings
opts = detectImportOptions("log.txt", 'Delimiter', '|', 'NumHeaderLines', 2);
opts.VariableTypes(2) = "double";
T = readtable("log.txt", opts);Use Options With Numeric Imports
opts = detectImportOptions("values.csv");
A = readmatrix("values.csv", opts);Using detectImportOptions with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how detectImportOptions changes the result.
Run a small detectImportOptions example, explain the result, then change one input and compare the output.
FAQ
Is the returned value a MATLAB import-options object?⌄
RunMat represents import options as a scalar struct so field assignment and reader consumption work naturally in the current runtime.
Can I use the same options with readmatrix?⌄
Yes for numeric text imports. readmatrix consumes fields such as Delimiter, NumHeaderLines, Range, and TreatAsMissing and ignores table-specific fields.
Does detection read the whole file?⌄
RunMat currently reads the file into host memory and samples the parsed rows, matching the existing readtable import pipeline.
Can detection options be GPU-resident?⌄
No. Resident path or option values, including nested values, are rejected before provider or file access.
Related Io functions
Tabular
arrayDatastore · csvread · csvwrite · dlmread · dlmwrite · fileDatastore · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite
Repl Fs
addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines
Import
Json
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how detectImportOptions is executed, line by line, in Rust.
- View the source for detectImportOptions in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.