aloop: a pedestrian automatic for loop creator

版本 1.0.0.0 (2.9 KB) 作者: us
automatically creates / executes a for loop construct
4.4K 次下载
更新时间 2003/6/13

查看许可证

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];

引用格式

us (2024). 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. 检索时间: .

MATLAB 版本兼容性
创建方式 R13
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0

enhanced help again