[問題] 關於m-file的執行

看板MATLAB作者 (看到鬼)時間12年前 (2011/11/28 07:20), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
小弟找到下面這個m-file, 裡面的 vigenere 也是另一個m-file function ciphertext = encrypt(plaintext, key) v = vigenere; % Squeeze out everything except letters and the space character exclude = regexp(plaintext, '[^a-zA-Z ]'); plaintext(exclude) = []; % Make the key and the plaintext lower case, and convert to % numeric values. key = lower(key) - double('a') + 1; key(key < 0) = 27; plaintext = lower(plaintext) - double('a') + 1; plaintext(plaintext < 0) = 27; % Replicate the key so that it is as long as the plaintext. keyIndex = mod(0:(numel(plaintext)-1), numel(key))+1; k = key(keyIndex); % Encrypt: C(n) = V(k(n), plaintext(n)) ciphertext = arrayfun(@(m,n) v(m,n), k, plaintext) - 1; ciphertext(ciphertext == 26) = double(' ') - double('a'); ciphertext = upper(char(ciphertext + double('a'))); 但當我輸入 plaintext = ['gdhse123'] 以及 key = [2 3 4 5 6 7] 時 他卻出現 " plaintext is undefined " 然後錯誤是發生在 exclude = regexp(plaintext, '[^a-zA-Z ]') 這一行裡面 想請教各位大大 是我的 plaintext 輸入的格是錯誤嘛??? 如果是的話 請問一下要如何改變呢??? 還是我有其他另外沒有注意到的錯誤呢? 謝謝各位大大 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 134.88.248.240
文章代碼(AID): #1EqiNJBQ (MATLAB)