2009年2月25日 星期三

FORMAT Set output format

利用 format 指令, 可以更改預設的數值顯示方式。
FORMAT with no inputs sets the output format to the default appropriate for the class of the variable. For float variables, the default is FORMAT SHORT.

FORMAT does not affect how MATLAB computations are done. Computations on float variables, namely single or double, are done in appropriate floating point precision, no matter how those variables are displayed. Computations on integer variables are done natively in integer. Integer variables are always displayed to the appropriate number of digits for the class, for example, 3 digits to display the INT8 range -128:127.

FORMAT SHORT and LONG do not affect the display of integer variables.

FORMAT may be used to switch between different output display formats of all float variables as follows:

FORMAT SHORT Scaled fixed point format with 5 digits.

FORMAT LONG Scaled fixed point format with 15 digits for double and 7 digits for single.

FORMAT SHORT E Floating point format with 5 digits.

FORMAT LONG E Floating point format with 15 digits for double and 7 digits for single.

FORMAT SHORT G Best of fixed or floating point format with 5 digits.

FORMAT LONG G Best of fixed or floating point format with 15 digits for double and 7 digits for single.

FORMAT SHORT ENG Engineering format that has at least 5 digits and a power that is a multiple of three

FORMAT LONG ENG Engineering format that has exactly 16 significant digits and a power that is a multiple of three.

FORMAT may be used to switch between different output display formats of all numeric variables as follows:

FORMAT HEX Hexadecimal format.

FORMAT + The symbols +, - and blank are printed for positive, negative and zero elements. Imaginary parts are ignored.

FORMAT BANK Fixed format for dollars and cents.

FORMAT RAT Approximation by ratio of small integers.

FORMAT may be used to affect the spacing in the display of all variables as follows:

FORMAT COMPACT Suppresses extra line-feeds.

FORMAT LOOSE Puts the extra line-feeds back in.

 

控制 Matlab 的顯示方式

1. 顯示或不顯示運算結果
 在同一行撰寫多個 Matlab 指令, 必須用 逗號 (,) 隔開, 如果不想讓運算結果顯示在螢幕上, 就必須在指令的後面加上分號 (;)

2. 指令跨行的控制
 如果指令太長, 無法在一行中把指令撰寫完畢, 可以用跨行字元 (...) "連續三個點", 來表示指令是跨行的。

3. 資料輸出格式的控制: format 指令