.. highlightlang:: us .. index:: fread .. index:: fread_char .. index:: fread_char8 .. index:: fread_float64 .. index:: fread_float32 .. index:: fread_int8 .. index:: fread_uint8 .. index:: fread_int16 .. index:: fread_uint16 .. index:: fread_int32 .. index:: fread_uint32 .. index:: fread_int64 .. index:: fread_uint64 .. _fread: fread ===== .. us.tag fread ENGLISH ffiles Changed420 Changed500 Changed582 :ref:`fread` reads data from a file. .. function:: 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) .. us.return **Return Value** *dat* is a scalar string, if *ssType* is "char" or in all other cases a real vector. .. us.params **Parameters** .. uparam:: fh Identifies the file. .. uparam:: ssType *ssType* is one of the following strings: .. list-table:: :header-rows: 1 * - Value - Old Name - Meaning * - "float64" - "double" - 8 Bytes floating point value, :ref:`fread_float64 `. * - "float32" - "float" - (4 Bytes) * - ``-`` - "real48" - (6 Bytes) * - "char" - "char" - 2 Bytes-Unicode character, :ref:`fread_char `. * - "char8" - "char8" - 1 Byte, :ref:`fread_char8 `, see also :ref:`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) .. uparam:: 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. .. us.example **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 .. us.history **History** .. list-table:: :header-rows: 1 * - 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 :ref:`strtrim` function can be used to truncate the string at the first 0-character. .. seealso:: :ref:`overview-binary-and-text-files`, :ref:`fopen`, :ref:`fwrite`, :ref:`fseek`, :ref:`feof` :sub:`id-1864235`