fread reads data from a file.
Return Value
dat is a scalar string, if ssType is “char” or in all other cases a real vector.
Parameters
Identifies the file.
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 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