作者Gwaewluin (神无月 孝臣)
看板MATLAB
标题Re: [问题] 当回圈的指标i不是正整数时?
时间Sat Mar 24 19:47:54 2012
※ 引述《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)
1F:推 Leedavid:感谢~ 03/24 23:55