精華區beta MATLAB 關於我們 聯絡資訊
※ 引述《cys (白月光 )》之銘言: : n=220; : for i=1:n-4; : mv=mean(a(i:i+4)); : end; : 請問大家 : 如果我有一個行向量a : 想對向量裡的元素做移動平均 (1~5 2~6.... 216~220的平均數) : 上述的迴圈寫法有錯嗎 : 跑出來的結果 : workspace僅有第216~220的平均數一個值 : 跟原本預期的會有一個 216 X 1 的向量不一樣 : 而只有在command window裡有列出每個平均數 : 要如何解決這個問題 讓我能在workspace裡得到一個216 X 1 的向量呢? : 謝謝回答~~ ^^ 因為每次迴圈的時候 mv內的值都被新的取代了 改成這樣試試看吧 mv(i)=mean(a(i:i+4)); 這樣跑出來的才會是個1*216的矩陣 -- Deserves death! I daresay he does. Many that live deserve death. And some die that deserve life. Can you give that to them? Then be not too eager to deal out death in the name of justice, fearing for your own safty. Even the wise cannot see all ends. Gandalf to Frodo -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.131.231.183
cys:謝謝你 我解決了 感謝囉 ^^ 11/21 18:18