From: Jean-Philip Dumont on 19 Jun 2010 13:50 "us " <us(a)neurol.unizh.ch> wrote in message <hviv2g$e2l$1(a)fred.mathworks.com>... > "Jean-Philip Dumont" <jean-philip.dumont(a)hec.ca> wrote in message <hviujd$f9m$1(a)fred.mathworks.com>... > > Hi, > > > > I'm doing a loop from "i"=0 to 0.5 with steps of 0.01. (0:0.01:0.5) > > > > For every "i", i'm putting the maximum likelihood value I calculated into a matrice. In order to have real indices, I multiply "i" by a hundred and add 1. (100*i+1). By doing this, I end up with indices of 1,2,3,4,.....,51 which is allowing me to put my values calculated in the right place. > > > > But something weard is happening while doing this really simple multiplication. > > > > when i=0.14, 100*0.14+1 it is giving me 15.0000 instead of just 15. Because of this, when the loop hits i=0.14, it gives me an error saying Subscript indices must be real. The same thing happens at the value i=28, 29 and 33 but nowhere else. > > > > Can someone help me on that and tell me why it does this? > > > > Thank you very much! > > one of the most simple solutions > - add an index counter... > > ix=0:.5*pi:pi; > r=nan(numel(ix),1); > ic=0; > for i=0:.1*pi:pi > ic=ic+1; > r(ic)=i; > end > > us Great! With the explanation I got on why I had 15.000, i just added in the coordinates of my loop the function round : for j=0:0.01:0.5 ThetaTests(7,1) = j; Ls(round(100*j+1),1)=LiklihoodEval(ThetaTests,SP500LogDiff,p,q); end Thank you for your help!
From: Steven Lord on 22 Jun 2010 15:30 "Jean-Philip Dumont" <jean-philip.dumont(a)hec.ca> wrote in message news:hvj00t$chg$1(a)fred.mathworks.com... > "us " <us(a)neurol.unizh.ch> wrote in message > <hviv2g$e2l$1(a)fred.mathworks.com>... >> "Jean-Philip Dumont" <jean-philip.dumont(a)hec.ca> wrote in message >> <hviujd$f9m$1(a)fred.mathworks.com>... *snip* > Great! With the explanation I got on why I had 15.000, i just added in the > coordinates of my loop the function round : > > for j=0:0.01:0.5 > ThetaTests(7,1) = j; > Ls(round(100*j+1),1)=LiklihoodEval(ThetaTests,SP500LogDiff,p,q); > end Rather than ROUNDing in your index, why not scale your loop indices inside your function call? for j = 0:1:50 ThetaTests(7, 1) = (j/100); Ls(j+1, 1) = ... -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: Jean-Philip Dumont on 22 Jun 2010 16:06 "Steven Lord" <slord(a)mathworks.com> wrote in message <hvr2vs$1ht$1(a)fred.mathworks.com>... > > "Jean-Philip Dumont" <jean-philip.dumont(a)hec.ca> wrote in message > news:hvj00t$chg$1(a)fred.mathworks.com... > > "us " <us(a)neurol.unizh.ch> wrote in message > > <hviv2g$e2l$1(a)fred.mathworks.com>... > >> "Jean-Philip Dumont" <jean-philip.dumont(a)hec.ca> wrote in message > >> <hviujd$f9m$1(a)fred.mathworks.com>... > > *snip* > > > Great! With the explanation I got on why I had 15.000, i just added in the > > coordinates of my loop the function round : > > > > for j=0:0.01:0.5 > > ThetaTests(7,1) = j; > > Ls(round(100*j+1),1)=LiklihoodEval(ThetaTests,SP500LogDiff,p,q); > > end > > Rather than ROUNDing in your index, why not scale your loop indices inside > your function call? > > for j = 0:1:50 > ThetaTests(7, 1) = (j/100); > Ls(j+1, 1) = ... > > -- > Steve Lord > slord(a)mathworks.com > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ > To contact Technical Support use the Contact Us link on > http://www.mathworks.com > Didn't though of that. Thank you for the tip!
|
Pages: 1 Prev: calculated surface area Next: element-by-element multiplication |