Matlab efficient for loop possible or many needed? -
for = 1:length(startidx) j = 1:length(date(startidx(i):cutoffidx(i))) k = date(startidx(i):cutoffidx(i)); try shortidx(j)=find(and(and(and(and(and(jam>=1.2,jam<=2.3),expiration==xdates(i)),option_type=='c'),jamsym==1),quote_date==k(j)),1); catch warning('not present') shortidx(j)=0; end end end let's i = 1:4. on first pass through i, fine. when i = 2, overwriting stored shortidx data created when i 1. j length of each i, , k dates each i. tripped last part of try statement
quote_date==k(j) because when i turns 2, j reset 1. though k correct set of dates i, overwriting shortidx variable, instead of appending it. there way me solve efficiently? or need create independent loop each i? thank you.
save 2d array indexed i , j. on each pass of inner loop
shortidx(i, j) = someobscenelylongandstatement; for efficiency should preallocate shortidx before loops.
alternatively, make long 1d array, update indices
shortidx(length(startidx)*(i- 1) + j) = ... good luck!
Comments
Post a Comment