Real Number to N-digit String

Version 1.0.0.0 (1.26 KB) by Omar
num2strN( input , N ) Floors a real number and converts it to an N-digit string.
312 Downloads
Updated 28 Jun 2010

View License

Floors a real number and converts it to an N-digit string, e.g. for N=3 input 1 becomes 001, 34 becomes 034 and 876 remains the same.
Can be used for various purposes. I wrote it for writing images in a folder such that they have names image001.jpg, image002.jpg, etc. I also used it to display the time in an MM:SS format:

tic
your_code
toc = timeElapsed;
[num2strN(round(timeElapsed/60),3) ':' num2strN(mod(timeElapsed,60),2)]

Cite As

Omar (2026). Real Number to N-digit String (https://www.mathworks.com/matlabcentral/fileexchange/28035-real-number-to-n-digit-string), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Version Published Release Notes
1.0.0.0