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.
2009年2月25日 星期三
FORMAT Set output format
利用 format 指令, 可以更改預設的數值顯示方式。
2008年9月29日 星期一
FOPEN: Open file
FOPEN 這個指令和 C 語言的用法並沒有甚麼不同, 傳回值則是一個整數,
FID = FOPEN(FILENAME)當 MATLAB 無法依照指令找到要開啟的檔案時, 就會傳回 -1, 寫程式時應該特別針對傳回值為 -1 時, 做特別處理。例如:
opens the file FILENAME for read access.
FILENAME can be a MATLABPATH relative partial pathname. If the file is opened for reading and it is not found in the current working directory, FOPEN searches down MATLAB's search path.
FID is a scalar MATLAB integer, called a file identifier. You use the fid as the first argument to other file input/output routines. If FOPEN cannot open the file, it returns -1.
fid=fopen(filename);就如同 C 語言一樣, FOPEN 指令也可以根據不同的需求, 設定不同的開啟模式。
if fid==-1
error('File does not exist or is not in your MATLAB path.');
end;
FID = FOPEN(FILENAME,PERMISSION)
opens the file FILENAME in the mode specified by PERMISSION.
PERMISSION can be:
'r' read
'w' write (create if necessary)
'a' append (create if necessary)
'r+' read and write (do not create)
'w+' truncate or create for read and write
'a+' read and append (create if necessary)
'W' write without automatic flushing
'A' append without automatic flushing
REPMAT: Replicate and tile an array
REPMAT 指令可以拆解成 replicate matrix, 顧名思義就是複製矩陣的意思,
注意: 上述式子中的分號代表換行的意思, 是 MATLAB 矩陣的輸入語法。
B = repmat(A,M,N) creates a large matrix B consisting of an M-by-N tiling of copies of A.將 matrix A 複製 M * N 個, 並以 M 行 N 列的方式排列。舉例來說:
A=[1, 5];B = [1, 5, 1, 5; 1, 5, 1, 5; 1, 5, 1, 5]
B=repmat(A, 3, 2);
注意: 上述式子中的分號代表換行的意思, 是 MATLAB 矩陣的輸入語法。
2008年9月28日 星期日
IMFINFO:Information about graphics file
透過 IMFINFO 這個指令, 我們可以獲得關於影像檔案的相關資訊。
我們發現 IMFINFO 傳回值都放到一個特定型態的結構之中。連按 inf 兩下, 就可以打開 Array Editor 視窗, 觀察 inf 的實際內容。
inf = imfinfo('twins.tif');觀察 workspace 中的變化,
我們發現 IMFINFO 傳回值都放到一個特定型態的結構之中。連按 inf 兩下, 就可以打開 Array Editor 視窗, 觀察 inf 的實際內容。
SIZE: Size of array
SIZE 這個指令傳回陣列的大小。我們用以下的例子來說明:
從圖片中我們可以看到 s 的值為 [256, 256, 3], 剛好就是 x 陣列的大小。
x=imread('twins.tif');
s=size(x);
從圖片中我們可以看到 s 的值為 [256, 256, 3], 剛好就是 x 陣列的大小。
訂閱:
文章 (Atom)