forked from ndwork/dworkLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindx2str.m
More file actions
37 lines (32 loc) · 996 Bytes
/
indx2str.m
File metadata and controls
37 lines (32 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function out = indx2str( indx, N )
% out = indx2str( indx, N )
%
% Converts index to a string the appropriate size for N with padded zeros
% For example, if N is 100, will convert indx=88 into '0880';
%
% Inputs:
% indx - the number to convert into a string
% N - the maximum indx that will be converted
%
% Outputs:
% out - string
%
% Example:
%
% N = 1000;
% for i=1:N
% disp([ 'Working on ', indx2str(i,N), ' of ', N ]);
% ... do important stuff here ...
% end
%
% Written by Nicholas - Copyright 2019
%
% This software is offered under the GNU General Public License 3.0. It
% is offered without any warranty expressed or implied, including the
% implied warranties of merchantability or fitness for a particular
% purpose.
if nargin < 2, disp( 'out = indx2str( indx, N )' ); end
nDigits = floor( log10( N ) ) + 1;
formatSpec = [ '%', num2str(nDigits), '.', num2str(nDigits), 'i' ];
out = num2str( indx, formatSpec );
end