IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
int2ord.m
Go to the documentation of this file.
1 %> @ingroup conversion string
2 %> @file
3 %> @brief Converts integer to ordinal number string
4 %>
5 %> @param idx Integer number
6 %> @return out String like '1st', '411th' etc
7 function out = int2ord(idx)
8 
9 mo10 = mod(idx, 10);
10 mo100 = mod(idx, 100);
11 if mo10 == 1 && ~(mo100 == 11)
12  s = 'st';
13 elseif mo10 == 2 && ~(mo100 == 12)
14  s = 'nd';
15 elseif mo10 == 3 && ~(mo100 == 13)
16  s = 'rd';
17 else
18  s = 'th';
19 end;
20 
21 out = sprintf('%d%s', idx, s);
function int2ord(in idx)