aloop: a pedestrian automatic for loop creator
par = aloop('com','-opt',lix1,...,lixX,...,lixN)
automatically creates / executes a
set of <commands> resulting from a
dynamic for-loop construct defined
by loop-indices <lix1>, ... <lixN>:
for p1 = lix1
for ...
for pN = lixN
par.com{n} = sprintf(com,p1,...,pN);
% -opt: '-R',lix1,...,lixN
% par.com{n} = sprintf(com,pN,...,p1);
% -opt: '-o',[3 1 2 ... pX],lix1,...,lixN
% par.com{n} = sprintf(com,p3,p1,p2,...,pX);
end
end
end
NOTE
<aloop> uses recursive calls. therefore, it is limited only by the
number of loop-arguments and NOT by the length of a single loop.
the limit can be adjusted by:
set(0,'recursionlimit',int_number); % [def: 500]
EXAMPLES
% create a simple <sprintf> statement
c=aloop('sprintf(''%2d/%7.3f > %s.%s''),','-c',...
1:2,pi*[1:3],{'apple' 'banana'},'AZ');
ALOOP> sprintf(' 1/ 3.142 > apple.A'),
ALOOP> sprintf(' 1/ 3.142 > apple.Z'),
ALOOP> sprintf(' 1/ 3.142 > banana.A'),
ALOOP> sprintf(' 1/ 3.142 > banana.Z'),
ALOOP> sprintf(' 1/ 6.283 > apple.A'),
ALOOP> sprintf(' 1/ 6.283 > apple.Z'),
ALOOP> sprintf(' 1/ 6.283 > banana.A'),
ALOOP> sprintf(' 1/ 6.283 > banana.Z'),
ALOOP> sprintf(' 1/ 9.425 > apple.A'),
ALOOP> sprintf(' 1/ 9.425 > apple.Z'),
ALOOP> sprintf(' 1/ 9.425 > banana.A'),
ALOOP> sprintf(' 1/ 9.425 > banana.Z'),
ALOOP> sprintf(' 2/ 3.142 > apple.A'),
ALOOP> sprintf(' 2/ 3.142 > apple.Z'),
ALOOP> sprintf(' 2/ 3.142 > banana.A'),
ALOOP> sprintf(' 2/ 3.142 > banana.Z'),
ALOOP> sprintf(' 2/ 6.283 > apple.A'),
ALOOP> sprintf(' 2/ 6.283 > apple.Z'),
ALOOP> sprintf(' 2/ 6.283 > banana.A'),
ALOOP> sprintf(' 2/ 6.283 > banana.Z'),
ALOOP> sprintf(' 2/ 9.425 > apple.A'),
ALOOP> sprintf(' 2/ 9.425 > apple.Z'),
ALOOP> sprintf(' 2/ 9.425 > banana.A'),
ALOOP> sprintf(' 2/ 9.425 > banana.Z'),
% to evaluate commands, use
for i=1:c.n
eval(c.com{i});
end
% -or- if commands end with delimiter <;> or <,>
eval([c.com{:}]);
% fill a matrix with <nan>s in the base workspace
% ... i know this wouldn't be the way to do it!
clear v
d=aloop('v(%d,%d) = nan;','-r',[1 3 5],1:2);
v =
NaN NaN
0 0
NaN NaN
0 0
NaN NaN
% fill vectors in a user defined order: [3 1 2]
d=aloop('[%d %d %d];','-o',[3 1 2],...
[1 3 5],1:2,2:4);
ALOOP> [2 1 1];
ALOOP> [3 1 1];
ALOOP> [4 1 1];
ALOOP> [2 1 2];
ALOOP> [3 1 2];
ALOOP> [4 1 2];
ALOOP> [2 3 1];
ALOOP> [3 3 1];
ALOOP> [4 3 1];
ALOOP> [2 3 2];
ALOOP> [3 3 2];
ALOOP> [4 3 2];
ALOOP> [2 5 1];
ALOOP> [3 5 1];
ALOOP> [4 5 1];
ALOOP> [2 5 2];
ALOOP> [3 5 2];
ALOOP> [4 5 2];
Cite As
us (2025). aloop: a pedestrian automatic for loop creator (https://www.mathworks.com/matlabcentral/fileexchange/3338-aloop-a-pedestrian-automatic-for-loop-creator), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 | enhanced help again |