matlab - Avoid counters in loops with mathematician rule -
i'm trying find mathematician formula avoid counter increment 1 step step loops (any number first element, last element , increment).
example 1 (one loop):
min=first element, max=last element , hop=increment (variable i)
with counter:
c = 1; = min:hop:max c = c + 1; end
without counter:
for = min:hop:max c = floor((i-min)/hop) + 1; end
example 2 (two loops):
mini=first element, maxi=last element , hopi=increment (variable i)
minj=first element, maxj=last element , hopj=increment (variable j)
with counter:
c = 1; = mini:hopi:maxi j = minj:hopj:maxj c = c + 1; end end
without counter:
for = mini:hopi:maxi j = minj:hopj:maxj x = (floor((i-mini)/hopi)+1); y = (floor((j-minj)/hopj)+1); c = x*y+(x-(floor((maxi-mini)/hopi)+1))*((floor((maxj-minj)/hopj)+1)-y); end end
any simplification c formula 2 loops?
any formula find c k loops, c(k)?
Comments
Post a Comment