Return an array of numbers which (effectively) count from 0 to N^M-1 in base N. The result should be returned in a matrix, with each column representing a number. Each element represents a digit of the number. Lower-indexed rows represent lower-significance digits.

Example 1 (Binary): countInBaseN(2,2) (counts from 0 to 3 in base 2)

ans =

     0     0     1     1
     0     1     0     1

Example 2 (Ternary): countInBaseN(2,3) (counts from 0 to 8 in base 3)

ans =

     0     0     0     1     1     1     2     2     2
     0     1     2     0     1     2     0     1     2

Solution Stats

665 Solutions

240 Solvers

Last Solution submitted on Feb 04, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers240

Suggested Problems

More from this Author1

Problem Tags

Community Treasure Hunt

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

Start Hunting!