importdata — Import numeric text data with optional headers.
A = importdata(filename) imports legacy numeric text files, returning either a numeric matrix or a structure containing imported data plus header metadata.
Syntax
A = importdata(filename)
A = importdata(filename, delimiterIn)
A = importdata(filename, delimiterIn, headerlinesIn)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
filename | StringScalar | Yes | — | File to import. |
delimiterIn | StringScalar | No | — | Delimiter to use for text files. |
headerlinesIn | IntegerScalar | No | — | Number of header lines to skip. |
Returns
| Name | Type | Description |
|---|---|---|
A | Any | Imported numeric matrix or import structure. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:importdata:InvalidArgument | Filename, delimiter, or header line arguments are malformed. | importdata: invalid argument |
RunMat:importdata:Io | The input file cannot be read. | importdata: unable to read file |
RunMat:importdata:Parse | Text content cannot be imported as supported numeric/header data. | importdata: unable to parse text data |
How importdata works
- Supports
importdata(filename),importdata(filename, delimiterIn), andimportdata(filename, delimiterIn, headerlinesIn). - Automatically detects comma, tab, semicolon, pipe, or whitespace delimiters from non-empty lines when no delimiter is supplied.
- Pure numeric files return a double tensor directly, matching MATLAB's convenient legacy behavior.
- Files with header rows return a struct with
data,textdata, and, when inferable,colheaders. - Files with leading row labels return a struct with
rowheadersand numericdata. - Recognizes
NaN,Inf,+Inf, and-Inf; empty numeric fields import asNaN. - Unsupported mixed text/numeric rows produce a descriptive parse error. Binary/image/audio/MAT import expansion should be handled by the dedicated import builtins as those domains mature.
Does RunMat run importdata on the GPU?
importdata does not launch provider kernels or participate in fusion.
GPU memory and residency
importdata is a host file-I/O source. It returns host tensors or structs and does not create GPU-resident arrays.
Examples
Import a plain numeric text matrix
A = importdata("values.txt")Import CSV data with a header row
S = importdata("run.csv");
S.colheaders
S.dataSpecify delimiter and header-line count
S = importdata("log.dat", '|', 2)Using importdata with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how importdata changes the result.
Run a small importdata example, explain the result, then change one input and compare the output.
FAQ
When does importdata return a struct?⌄
It returns a struct when header text, column headers, or row headers are present. Pure numeric files return a tensor.
How does delimiter detection work?⌄
RunMat samples non-empty lines and chooses a consistent comma, tab, semicolon, or pipe delimiter; otherwise it falls back to whitespace splitting.
Does this replace readmatrix?⌄
No. importdata preserves MATLAB's legacy convenience behavior. Prefer readmatrix or readtable for new code that needs explicit import options.
Related Io functions
Import
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
Tabular
csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · readmatrix · spreadsheetImportOptions · writecell · writematrix · xlsread
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite
Json
Archive
Http
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how importdata is executed, line by line, in Rust.
- View the source for importdata 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.