Read contents of a dbase (dbf) file, provisionally dbase III+, IV or V.
- fname should be the name of a valid dbase file; the file extension
isn’t required.
- recs can be an integer or logical array containing record numbers or
record indicators for those records that need to be returned. If omitted,
all records are read. Indices supplied in recs can be specified in
any order, but the returned data are sorted in order of records in the file.
- cols can be a logical, integer, cellstr or character array indicating
from which file columns the data should be returned. If a numeric array is
supplied, it is considered to be like a logical array if the maximum entry
value equals 1. Character arrays should have column names stacked in the
vertical (first) dimension. cols cellstr or char arrays can be
supplied in any order, yet the returned data column order matches that of
the columns order in the dbase file. For dbase files containing multiple
columns with the same name, specify a numeric or logical array to select
columns to be returned. If omitted, data from all file columns are
returned.
- If a value of 1 or true is entered for re, dbfread also tries to
return data from erased records. No guarantee can be given for these data
to be correct or consistent! If omitted, erased records are skipped.
- Return value data is a N+1 x M cellstr array where the uppermost row
contains the column names and the rest of the rows the record data.
- Optional return argument datinfo is a struct array containing various
information of the dbase file and record build-up.
Arguments recs and cols need not be as long as the number of
records and columns in the file, resp.; dbfread will stop reading data if
any of recs or cols (if supplied) is exhausted.
Sometimes dbase files contain records indicated as being erased. The data
in such records is silently skipped, unless the re flag is set
and/or recs is supplied and erased records happen to be present in the
requested record numbers.
Examples:
A = dbfread ("file.dbf");
(returns all data in file.dbf in array A)
[A, B] = dbfread ("file.dbf", [], ["colB"; "colF"]);
(returns all data in columns named "colB" and "colF" from
file.dbf in array A and information on the database
build-up in struct B)
A = dbfread ("file.dbf", [0 1 0 0 1 0 0]);
-or-
A = dbfread ("file.dbf", [2 5]);
(returns data from record numbers 2 and 5 in
file.dbf in array A)
A = dbfread ("file", [0 1 0 0 1 0]);
(returns data from record numbers 2 and 5 in
file.dbf in array A)
[~, B] = dbfread ("file.dbf", 0);
(to returns info on column names and number of
records, plus more info)
[A] = dbfread ("file", [], {"Header1", "Col5"});
(returns data from columns with names (headers)
Header1 and Col5, resp.)
See also: xlsread.