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 supported overrides including
FileType,Delimiter,NumHeaderLines,Range,Sheet,VariableNames,VariableTypes,ReadVariableNames,ReadRowNames,TreatAsMissing,VariableNamingRule,TextType,DatetimeType,EmptyLineRule, andEncoding. - 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; unsupported MATLAB option fields are not emitted.
Does RunMat run detectImportOptions on the GPU?
No acceleration provider hooks are used.
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.
Related Io functions
Tabular
csvread · csvwrite · dlmread · dlmwrite · readmatrix · spreadsheetImportOptions · writecell · writematrix · xlsread
Repl Fs
addpath · cd · copyfile · delete · dir · exist · fullfile · genpath · getenv · ls · mkdir · movefile · path · pwd · rmdir · rmpath · run · savepath · setenv · tempdir · tempname · uigetfile · uiputfile
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite
Import
Json
Archive
Http
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.