readascii

Reads ascii files and prepares them for load compatibility.
7K Downloads
Updated 30 Mar 2006

No License

Reads ASCII Files

USAGE:
argout = readascii(argin)

DESCRIPTION:
Reads an ascii file and returns (if nargout==1)
a structure with several fields including the
headers, text and nuemrica data.
If the name for an out-file is given,
the file is changed for MatLab load
compatibility commenting all "text" lines and
inserting NaN'. The out file may be saved as
binary, which only saves the data of the in-file.

INPUT VARIABLE:
argin is a structure array with fields:
infile = file to be read
outfile = name of out-file (only if given)
outperm = permision for out file used for fopen.m
examples - 'w', 'wb', 'a+', etc
default - 'w'
outprec = precision for out file used for fwrite.m
examples - 'uchar', 'int8', 'single', 'double'
default - 'uchar'
old = text or numbers that want to be replaced
If more than one number or text needs to be
replaced, old may be given as a cell array
examples - -9999, {'0000','-----'}
default - '*****'
new = text or number that replaces old
default - 'NaN'

OUTPUT VARIABLE:
argout is a structure array with the same fields as argin, plus:
header(s) = heading of file and/or any row with characters other
than e that are commented in an ascii out file
any line starting with % or any non alphabet characters
text = string data in file
data = vector or matrix with data read from file
flag = text indicating whether all data was read,
if there exist rows with different
number of columns in the in file, and
the amount of data written to a binary file

NOTES:
Using outfile == infile is valid but slows
the program down considerably.
The uigetfile dialog is invoked if nargin==0.
Commenting a linea twice or any data linea with NaN' is avoided.
Only permits writing to binary file if the ascii file contains
only one data size

Copy-Left, Alejandro Sanchez

Cite As

Alex Sanchez (2024). readascii (https://www.mathworks.com/matlabcentral/fileexchange/4068-readascii), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

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

lots of updates