A = fread(fid)
[A,count] = fread(fid,size,'precision')
A = fread(fid)
reads binary data from the specified file and writes it into matrix A
. fid
is an integer file identifier obtained from fopen
.
[A,count] = fread(fid,size,'precision')
attempts to read size
number of elements of the specified precision
. count
is the number of elements successfully transferred.
The size
argument can be
------------------------------------------------------------ n ReadsIfn
elements into a column vector. inf Reads to the end of the file, resulting in a column vector containing the same number of elements as are in the file. [m,n] Reads enough elements to fill anm-by-n
matrix, fill ing in elements in column order, padding with zeros if the file is too small to fill the matrix. ------------------------------------------------------------
size
is not specified, Inf
is assumed.
The 'precision'
argument specifies the numeric precision of the values read. precision
controls the number of bits read for each value and the interpretation of those bits as an integer, a floating-point value, or a character. The table on the next page lists the allowable precision
strings and their meanings.
Note that if fread
reaches the end of the file and the current input stream does not contain enough bits to write out a complete matrix element of the specified precision, fread
pads the last byte or element with zero bits until the full value is obtained. If an error occurs, reading is done up to the last full value.
Numeric precisions are hardware specific; they depend on how numbers are represented in the architecture of your specific computer. Although the following table indicates certain common precision values, be aware that these values are not necessarily correct for your system except for 'float32'
and 'float64'
, which have absolute precision values and are not hardware specific, although these values may not be supported on all architectures.
This section assumes that you know the appropriate numeric precision for your hardware. If you are not familiar with the numeric precision for your hardware, refer to the hardware reference manual.
For convenience, MATLAB accepts some C and FORTRAN data type equivalents for the MATLAB precisions listed. If you are a C or FORTRAN programmer, you may find it more convenient to use the names of the data types in the language with which you are most familiar.
---------------------------------------------------------------------- MATLAB C or FORTRAN Interpretation ---------------------------------------------------------------------- 'char' 'char', 'char*1' Character; 8 bits (signed or unsigned, depending on the architecture) 'schar' 'signed char' Signed character; 8 bits 'uchar' 'unsigned char' Unsigned character (default); 8 bits 'short' 'short' Integer; 16 bits 'ushort' 'unsigned short' Unsigned integer; 16 bits 'int' 'int' Integer; 16 or 32 bits 'uint' 'unsigned int' Unsigned integer; 16 or 32 bits 'long' 'long' Integer; 32 bits 'float' 'float' Floating-point value; 32 bits 'ulong' 'unsigned long' Unsigned integer; 32 bits 'float32' 'real*4' 32-bit floating-point value 'double' 'double' Long floating-point value; 64 bits 'float64' 'real*8' 64-bit floating-point value 'intN' Signed integer,N
bits wide 'uintN' Unsigned integer,N
bits wide. ----------------------------------------------------------------------
N
represents a value between 1 and 64. In addition, the following specific equivalents prevail:
---------------------------------------- 'int8' 'integer*1' Integer; 8 bits. 'int16' 'integer*2' Integer; 16 bits. 'int32' 'integer*4' Integer; 32 bits. 'int64' 'integer*8' Integer; 64 bits. ----------------------------------------
fclose
,ferror
,fopen
,fprintf
,fscanf
,fseek
,ftell
,fwrite
,sprintf
,sscanf
(c) Copyright 1994 by The MathWorks, Inc.