Free format read - ffread.m

版本 1.0.0.0 (3.1 KB) 作者: Miroslav Balda
ffread.m is applicable for reading character information from strings or files.
3.1K 次下载
更新时间 2007/6/20

查看许可证

Free-format-read function reads data of the known structure from an input, which may be either ASCII file or a string. Individual items may be numbers, words or strings. Almost any character may serve as a delimiter. The same holds even for a decimal point in real numbers. The function recognizes types of the read data. An attempt to read item after the physical end of data is signalized by returned character 127.

Forms of a call:
~~~~~~~~~~~~~~~~

First entry:
ffread(name);
name = file name of the input file or string of data;
default delimiters of items are ' ' or 'tab' 'cr' 'lf',
default decimal point is '.'
ffread(name,delim);
delim = user's delimiter of items
ffread(name,delim,point);
point = user's decimal point character (default '.')

Other entries:
data = ffread;
data = single item = number,
word = string without a pair of single quotes
string
data = ffread(n);
n = number of items to be read,
data = column of n read items as
i. n-vector of numbers or
ii. n-cell array of strings
Example:
~~~~~~~~
Given the file 'test.txt' containing 6 lines:
% Testing example for ffread
WORD % word (string without single quotes and spaces)
'This is a test' % string
This is a cell array% multiple words = cell array
123,45e-2; 1 2; 3 % ',' will be converted into '.'
4; 5 6 % ';' will be converted into ' '

The file 'test.txt' may be read by the following script:
ffread('test.txt', ';', ','); % file name, item delim, dec. point char.
w = ffread; % reads word WORD into w as string
s = ffread; % reads string into s
c = ffread(5); % cell array of 5 words
a = ffread; % reads one real number
v = (ffread(6)).';% row vector v of 6 elements
err = ffread % error! char(127) = true data already finished

引用格式

Miroslav Balda (2024). Free format read - ffread.m (https://www.mathworks.com/matlabcentral/fileexchange/9034-free-format-read-ffread-m), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R14
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0

Improved code and help, screenshot added