CounterInBase: Counting in arbitrary base

버전 1.1.0.0 (31.4 KB) 작성자: Petr Posik
Counter in arbitrary base with a convenient interface. The counter state can be saved to disc.
다운로드 수: 446
업데이트 날짜: 2010/2/8

라이선스 보기

A simple pseudo-class (using function handles and nested functions) representing a counter in an arbitrary base. Useful e.g. for enumerating numbers in certain base.

c = CounterInBase(3)
Creates a new counter with base 3 and resets its state to 0.

c.next(), or
c.next(1)
Returns the state of the counter and increments it by 1.

c.next(0)
Returns the state of the counter and does not change its state.

c.next(20)
Returns a matrix of the next 20 numbers and advances the state of the counter by 20.

c.save('filename')
Saves the counter state to disc. If no filename is given, it uses the default name 'CounterInBaseState'.

c.load('filename')
Loads the previously stored counter state from disc. If no filename is given, it loads from file with the default name 'CounterInBaseState'.
NOTE: To be able to call the c.load() method, the counter must first exist: c.load() must be preceded by the call to c = CounterInBase(x), i.e. the c counter may be in any state with any base.

Example:

>> c = CounterInBase(3);
>> c.next()
ans =
0
>> c.next()
ans =
1
>> c.next()
ans =
2
>> c.next()
ans =
1 0
>> c.next(3)
ans =
1 1
1 2
2 0
>> c.next(4)
ans =
0 2 1
0 2 2
1 0 0
1 0 1
>> c.next(0)
ans =
1 0 2
>> c.next(0)
ans =
1 0 2

인용 양식

Petr Posik (2024). CounterInBase: Counting in arbitrary base (https://www.mathworks.com/matlabcentral/fileexchange/26603-counterinbase-counting-in-arbitrary-base), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R14
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.1.0.0

The original archive contained the .svn directory by mistake.

1.0.0.0