Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

# Parameter Iterator (paramiterator) 1.0

Date Added: July 30, 2013  |  Visits: 250

Flattens arbitrarily nested loops into a single loop that iterates over all combinations of loop parameters.Makes it very easy to change the iteration parameters without rewriting loops, reindenting code, updating indices, etc.Very convenient for simulation problems where the parameters being tested frequently change, but the computation stays the same.Nested loop code like this:avalues = [1 2]; bvalues = [10 20]; cvalues = [100 200 300];for ai = 1:length(avalues) for bi = 1:length(bvalues) for ci = 1:length(cvalues) scoretable(ai,bi,ci) = avalues(ai) + bvalues(bi) + cvalues(ci); end endendCan be flattened into this, and any parameter can be added or removed by changing only paramvariables and paramvalues:paramvariables = {'A' 'B' 'C'};paramvalues = { {1 2} {10 20} {100 200 300}};piter = paramiterator(paramvariables,paramvalues);for i = 1:length(piter) setvalues(piter,i); scorelist(i) = A + B + C;endscoretable = listtotable(piter,scorelist);Results can be easily displayed with displaytable (http://www.mathworks.com/matlabcentral/fil...20-displaytable).You can now test whether a parameter has changed since the last iteration, before running some computation. This is like nesting the computation within only some of the loops, making paramiterator a full replacement for nested loops.

 Requirements: No special requirements Platforms: Matlab Keyword: 039a039,  039b039,  Added,  Bvaluesbi,  Changing,  Cvaluesci,  Endendcan,  Flattened,  Lengthpiter,  Nesting,  Parameter,  Paramiteratorparamvariablesparamvaluesfor,  Paramvalues,  Paramvaluesparamvariables,  Paramvariables,  Piter,  Removed,  Scorelisti,  Setvaluespiteri Users rating: 0/10