fread¶
fread reads data from a file.
-
dat = fread(fh, ssType)
-
dat = fread(fh, ssType, n)
-
dat = fread_char(fh, n)
-
dat = fread_char8(fh, n)
-
dat = fread_float64(fh, n)
-
dat = fread_float32(fh, n)
-
dat = fread_int8(fh, n)
-
dat = fread_uint8(fh, n)
-
dat = fread_int16(fh, n)
-
dat = fread_uint16(fh, n)
-
dat = fread_int32(fh, n)
-
dat = fread_uint32(fh, n)
-
dat = fread_int64(fh, n)
-
dat = fread_uint64(fh, n)
Return Value
dat is a scalar string, if ssType is “char” or in all other cases a real vector.
Parameters
-
fh
Identifies the file.
-
ssType
ssType is one of the following strings:
Value Old Name Meaning “float64” “double” 8 Bytes floating point value, fread_float64. “float32” “float” (4 Bytes) -
“real48” (6 Bytes) “char” “char” 2 Bytes-Unicode character, fread_char. “char8” “char8” 1 Byte, fread_char8, see also mem_get. “int8” -
(1 Byte) “uint8” “uchar” (1 Byte) “int16” “short” (2 Bytes) “uint16” “ushort” (2 Bytes) “int32” “int, long” (4 Bytes) “uint32” “uint, ulong” (4 Bytes) “int64” -
(8 Bytes) “uint64” -
(8 Bytes)
-
n
n defines the number of data objects to be read. If n is not specified (or if n <= 0) the complete file will be read beginning at the current position.
Example
fh = fopen("/test.bin", "wb");
rvValues = 1:100; // 1,2,3,4,...
fwrite(fh, "short", rvValues); // writes 100 short values
fclose(fh);
fh = fopen("/test.bin", "rb");
rvValues = fread(fh, "short", 100); // reads 100 short
fclose(fh); // values
History
Version | Description |
---|---|
5.8.2 | New type “char8”. |
4.2.0 | If ssType == “char” is true the result string will not be truncated at the first 0-character. The strtrim function can be used to truncate the string at the first 0-character. |
See also
id-1864235