aloop: a pedestrian automatic for loop creator

버전 1.0.0.0 (2.95 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