ASCII code n n n double ASCII char
字串和其ASCII code n n n double 指令: 檢視字串變數的儲存內容(即 ASCII 內碼) char 指令: 將 ASCII 內碼轉回字串形式 範例10 -6: string 106. m sentence = 'I''ve got a date!'; sentence. Ascii = double(sentence); %檢視 sentence 的 ASCII 碼 sentence 2 = char(sentence. Ascii) % 將 ASCII 碼轉回字串形式 sentence 2 = I've got a date!
字元與字串的基本概念-eval n n eval 指令: 直接“執行”某一特定字串,其效果就如同直接在 MATLAB 指 令視窗內輸入此一特定字串 eval 指令特別適用於在 for-loop 內自動產生有規律的變數名稱 範例10 -11: string 111. m clear all for i = 3: 6 % 清除所有變數 eval(['x', int 2 str(i) , '= magic(' , int 2 str(i) , ') ; ']); end whos x* Name x 3 x 4 x 5 x 6 Size 3 x 3 4 x 4 5 x 5 6 x 6 Bytes 72 128 200 288 Class double array Grand total is 86 elements using 688 bytes n x 3 , x 4 , x 5 , x 6 都是在 for-loop 中產生的變數,分別代表維度為 3× 3、4× 4、5× 5、6× 6 的魔方陣
字串的分解 n n n strtok 指令: 根據一給定的分界字元(Delimiting Characters),將 一字串拆解成數個字串,預設分界字元為空白字元 strvcat 指令: 將拆解下來的字串內容(即儲存在字串變數 chopped 中) 加到二維字元陣列 parsed 中 範例10 -24: string 306. m input_string = 'ee cs econ stat me'; remainder = input_string; parsed = ''; % 建立一空字元陣列 while (any(remainder)) [chopped, remainder] = strtok(remainder); parsed = strvcat(parsed, chopped); end parsed = ee cs econ stat me
- Slides: 19