No BSD License  

Highlights from
int2strz.m

3.66667

3.7 | 3 ratings Rate this file 2 Downloads (last 30 days) File Size: 2.05 KB File ID: #12973
image thumbnail

int2strz.m

by Carlos Adrian Vargas Aguilera

 

12 Nov 2006 (Updated 12 Mar 2008)

Same as int2str but with zero padding to the left.

| Watch this File

File Information
Description

This is a really simple program that makes the same as int2str but pads with zeros those integers with less digits than the maximum one.

It is useful (I hope) when our program reads files with names like: xxx001.dat, xxx002.dat, ..., xxx099.dat, xxx100.dat, etc., and we don't want to make use of if's to put zeros to int2str outputs (great isn't it).

int2strz(X,N) pads up to N digits (see the screenshot).

Acknowledgements
This submission has inspired the following:
daylightGMT.m
MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
14 Nov 2006 Jérôme Briot

Did you look at the documentation ?

X=[0 1 11 111]'

num2str(X,'%05d')
% or
sprintf('%05d',X')

IMHO, you should remove this submission.
Jérôme

14 Nov 2006 Jérôme Briot

Sorry, should read :

sprintf('%05d\n',X)

Jérôme

15 Nov 2006 Fco. Camacho

Yes jerome, but for us that doesn't like or want to write or read or simply don't understand thinks like '%..d', this is a beauty option and more readable. Question: why you don't complain about the int2str(x) function? We can do the same with num2str(round(x)) don't you think???

17 Sep 2008 Brien Polk

i use it all the time... thank you

Please login to add a comment or rating.
Updates
12 Mar 2008

Fixed minor bug for no numeric inputs, or a single zero.

Tag Activity for this File
Tag Applied By Date/Time
strings Carlos Adrian Vargas Aguilera 22 Oct 2008 08:48:46
int2str Carlos Adrian Vargas Aguilera 22 Oct 2008 08:48:46
sprintf Carlos Adrian Vargas Aguilera 22 Oct 2008 08:48:46
zero padding Carlos Adrian Vargas Aguilera 22 Oct 2008 08:48:46
integer Carlos Adrian Vargas Aguilera 22 Oct 2008 08:48:46
num2str Carlos Adrian Vargas Aguilera 22 Oct 2008 08:48:46

Contact us at files@mathworks.com