There are three different things that you could keep in mind when talking about the βformatβ of a number: the display format, the format for storing variables in memory (ie, the data type / class) and the format for storing a data file. I will review each ...
Display Format: As already mentioned by Amro , the display format can be configured using FORMAT . However, this only affects the display of numbers, and not how they are stored in memory.
Variable types / classes: There are a number of numerical classes , both floating point and signed / unsigned integer, which variables can use. By default, MATLAB variables are stored as double-precision floating-point numbers. To convert to other types, you can use the variable type as a function to change the value. For example, a = uint8(0); converts 0 to an 8-bit unsigned integer type and stores it in a , and b = single(pi); converts the value of pi to one-point and stores it in b .
File storage format: When reading / writing numerical values ββin files, the file type affects its storage. The binary file (written and read using FWRITE and FREAD ) stores the full binary representation of the number and can thus be represented as exactly the same type that is stored in memory as a variable (double precision, single-point, 8-bit integer, etc. .).
Alternatively, a text file (written and read using FPRINTF and FSCANF , among other functions) will save the value in a string format, which you must specify when outputting the values ββto a file. You can specify precision numbers, as well as the format (for example, exponential notation or hexadecimal). The documentation for FPRINTF defines these output formats.
source share