Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are three different things you could potentially be referring to when you talk about the "format" of a number: the display format, the variable storage format in memory (i.e. the data type/class), and the storage format in a data file. I'll address each...</p> <ul> <li><p><strong>Display format:</strong> As already mentioned by <a href="https://stackoverflow.com/questions/1480177/how-do-i-go-from-1-4795e004-to-14795-00/1480179#1480179">Amro</a>, the display format can be adjusted with the <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/format.html" rel="nofollow noreferrer">FORMAT</a> command. However, this only affects how the numbers are <em>displayed</em>, not how they are <em>stored in memory</em>.</p></li> <li><p><strong>Variable types/classes:</strong> There are a number of <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f2-12135.html" rel="nofollow noreferrer">numeric classes</a>, both floating point and signed/unsigned integer types, that 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 recast a value. For example, <code>a = uint8(0);</code> converts <code>0</code> to an 8-bit unsigned integer type and stores it in <code>a</code>, while <code>b = single(pi);</code> converts the value <code>pi</code> into single-precision and stores it in <code>b</code>.</p></li> <li><p><strong>File storage format:</strong> When reading/writing numeric values to files, the type of file affects how it will be stored. A binary file (written to and read from using <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fwrite.html" rel="nofollow noreferrer">FWRITE</a> and <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fread.html" rel="nofollow noreferrer">FREAD</a>) stores the complete binary representation of a number, and can thus represent it as exactly the same type as it is stored in memory as a variable (double-precision, single-precision, 8-bit integer, etc.).</p> <p>Alternatively, a text file (written to and read from using <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fprintf.html" rel="nofollow noreferrer">FPRINTF</a> and <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fscanf.html" rel="nofollow noreferrer">FSCANF</a>, among other functions) will store a value in a string format that you must specify when outputting the values to the file. You can specify the digits of precision, as well as the format (such as exponential notation or hexadecimal). The documentation for <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fprintf.html" rel="nofollow noreferrer">FPRINTF</a> specifies these output formats.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload