autotextread

Reads data file; auto-detects column names and formats from hdr.
3.2K Downloads
Updated 25 Aug 2005

No License

A wrapper around textread() that generates the format string for you automatically (each column is numeric or string); puts data into a struct with fields named for the column names given by the header line of the file. Has worked with 36-column data file. Based heavily on Solution number 26207, but that requires you know how many columns, and their formats, and does not scale well to more than about 10 columns.

For a similar utility for spreadsheets rather than text files, see Michael Robbins' spreadsheet2structure , File ID # 8127

Syntax example:

[a,colnames]=autotextread('autotextread_samp.txt')
where the file contains the following:
daynum stuff Adjective
1 .25 slimy
2 .23 speedy
3 1.00 super

You get:

a =
daynum: [3x1 double]
stuff: [3x1 double]
Adjective: {3x1 cell}
colnames = 'daynum' 'stuff' 'Adjective'

Cite As

Andrew Ross (2024). autotextread (https://www.mathworks.com/matlabcentral/fileexchange/1674-autotextread), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R12.1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Data Import and Analysis in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0

add reference to similar utility,
and incorporate suggestions from reviews.