indexing - Matlab not accepting whole number as index -


i using while loop index t starting 1 , increasing each loop. i'm having problems index in following bit of code within loop:

dt = 100000^(-1); t = 1; equi = false; while equi==false   ***some code populates arrays s(t) , i(t)***   t=t+1;    if (t>2/dt)         n = [s(t) i(t)];         np = [s(t-1/dt) i(t-1/dt)];         if sum((n-np).^2)<1e-5             equi=true;         end end 

first, code in "if" statement accessed @ t==200000 instead of @ t==200001.

second, expression s(t-1/dt) results in error message "subscript indices must either real positive integers or logicals", though (t-1/dt) whole , equals 1.0000e+005 . guess can solve using "round", worked before , doesn't work , i'd figure out why. thanks!

the expression s(t-1/dt) results in error message "subscript indices must either real positive integers or logicals", though (t-1/dt) whole , equals 1.0000e+005

is really? ;)

mod(200000 - 1/dt, 1) %ans = 1.455191522836685e-11 

your index not integer. 1 of things aware of when working floating point arithmetic. suggest reading excellent resource: "what every computer scientist should know floating-point arithmetic".

you can either use round did, or store 1/dt separate variable (many options exist).


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -