[讨论]这个bug求解

楼主: ljuyentintho (小刘)   2016-04-20 02:33:01
程式码如下:
r=3
a=3
O1 = ones(1, a);
AraPatient = ones(1,r*a);
for b= 1:2:(2*r-1)
for p =1:a:r*a
AraPatient(p) = (b-r)*O1(p);
end
end
AraPatient
我希望在这里AraPatient的结果是
[-2 -2 -2 0 0 0 2 2 2]
可是按下去之后的讯息是
Attempted to access O1(4); index out of bounds because numel(O1)=3.
这要怎么改?
谢谢
作者: celestialgod (天)   2016-04-20 09:38:00
p是1,4,7 O1长度只有3
楼主: ljuyentintho (小刘)   2016-04-20 20:33:00
可是我本来就希望长度是3阿
作者: celestialgod (天)   2016-04-20 20:35:00
所以去处理O1的标记阿= =
作者: sin55688 (单手挑藏獒)   2016-04-20 20:36:00
你都知道错误的原因了,那应该不难改吧
作者: celestialgod (天)   2016-04-20 20:36:00
例如改成 O1((p-1)/3+1)
楼主: ljuyentintho (小刘)   2016-04-20 20:49:00
喔喔我了解了
作者: sunev (Veritas)   2016-04-20 21:46:00
O1都是1,所以?
楼主: ljuyentintho (小刘)   2016-04-21 03:16:00
已解决 谢啦

Links booklink

Contact Us: admin [ a t ] ucptt.com