顯示具有 MatLab 標籤的文章。 顯示所有文章
顯示具有 MatLab 標籤的文章。 顯示所有文章

2007年4月2日 星期一

MATLAB Notes(2)

(參考: 張智星 MATLAB程式設計【入門篇】)
  • 一個 *.m 檔的 function 可以不只一個,但只有第一個 function 是可以給外面 call 的~ 其他的都是給裡面的 functions 互 call。
  • imread('test.jpg') 讀進來的矩陣 type 是 unit8/unit16 的資料型態,要做 frame difference 運算要先轉成 double。
  • A = imread('test.jpg'); B = rgb2gray(A); % RGB -> gray C = double(B)+1; % Because of the offset, must add 1 to convert to double
  • imshow: 轉成灰階之後,bitmap 改變,不能用原來的 image(A) 看圖,要用這個。
  • figure, imshow(B);
  • clc: clear command window
  • clear all / clear A: clear all variable or variable A
  • whos: see the workspace(working memory)
  • plot(A): 畫出 A 的曲線
  • type filename.txt: show the content of filename.txt
  • 關於檔案:
  • fid = fopen('filename.txt', 'w'); % 'w' for write, 'r' for read fprintf(fid, 'string string'); fclose(fid); dir('.'); % see all files at current directory, also include '.' and '..' dir('./*.jpg'); % see all JPEG files at current directory. files = dir('./*.jpg'); filename = files(1).name; % get the first file's name.

    (... 閱讀「MATLAB Notes(2)」全文)

    2007年4月1日 星期日

    MATLAB Notes(1)

    (參考: 張智星 MATLAB程式設計【入門篇】)
  • *.m 是 MATLAB 的程式檔案格式,依照內容又可分為 script 跟 function 兩種。
  • 呼叫 function 是用 "file name" (所以一個檔案只能有一個 function?)
  • 範例:(factTest.m)
    function output = fact(n) % FACT Calculate factorial of a given positive integer (for-loop version) output = 1; for i = 1:n,    output = output * i; end
    執行: (命令列)
    >> y = factTest(5) y =    120
  • function 沒有回傳值怎麼辦?

  • (... 閱讀「MATLAB Notes(1)」全文)