Prev: Erorr:Subscript indices must either be real positive integers or logicals
Next: Advantages of for and while loops?
From: dpb on 15 Apr 2010 17:54 Abdel-karim wrote: > I have the following statements but when execute them the erorr {{{ > Subscript indices must either be real positive integers or logicals }}} > appear > please if anyone has any comment or solution for this send to me > > %************************************************ > syms x; > for i=0:24 > E(i)=int(((0.09)*x^(2)*exp(-0.3*x)/factorial(2)),i,i+1); > end > %************************************************ > Thank you for everyone Well, the for loop begins with i=0 which pretty clearly is a problem... You'll need to arrange for the array to start at E(1) as Matlab doesn't use (or allow) 0-based arrays. --
From: Walter Roberson on 17 Apr 2010 10:18
Abdel-karim wrote: > anyone have an idea for my question please give me an answer thank you > again Old code: syms x; for i=0:24 E(i)=int(((0.09)*x^(2)*exp(-0.3*x)/factorial(2)),i,i+1); end Revised code: syms x; for i=1:25 E(i)=int(((0.09)*x^(2)*exp(-0.3*x)/factorial(2)),i-1,i); end |