看板 MATLAB 關於我們 聯絡資訊
※ 引述《Leedavid (大衛)》之銘言: : 先貼一小段程式 : y=zeros(2,8); : for i=[0.1 0.01] : for j=[-10 -5 5 10] : x=i+j; : y(i,j)=x; ← 這行matlab告訴我說i和j要正整數才行 : end : end : 我的迴圈i和j兩個不是正整數, : 然後經x運算後,其值要存入矩陣y, : 請問我現在要怎麼做才行? : 謝謝~ y=zeros(2,8); a = [ 0.1 0.01 ] ; <= 加這個 b = [ -10 -5 5 10 ] ; <= 加這個 for i = 1 : 2 <= 改這個 for j = 1 : 4 <= 改這個 x = a( i ) + b( j ) ; <= 改這個 y(i,j)=x; end end 請善用index 由於題意不清所以只能大概修改 譬如你的y矩陣在儲存後會有一半是0 但如果不用b矩陣修改 你的y矩陣在運算後維度會跑掉 -- On the surface, the scientist invests the power of his mind in a single miraculous idea and naturally begins to rise above his fellows. But the parasites say "NO! Discovery must be regulated! It must be controlled and finally surrendered." ─Andrew Ryan -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.170.14.145 ※ 編輯: Gwaewluin 來自: 1.170.14.145 (03/24 19:50)
Leedavid:感謝~ 03/24 23:55