Free format read - ffread.m

버전 1.0.0.0 (3.14 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