Extract the Digits of a Number

Athi on 17 Nov 2025 (Edited on 17 Nov 2025)
Latest activity Edit by Athi on 17 Nov 2025

Extracting the digits of a number will be useful to solve many Cody problems.
Instead of iteratively dividing by 10 and taking the remainder, the digits of a number can be easily extracted using String operations.
%Extract the digits of N
N = 1234;
d = num2str(N)-'0';
d =
1 2 3 4