summaryrefslogtreecommitdiff
path: root/graphics/pstricks/contrib/numericplots/MatlabFunctions/roman.m
blob: 1642a917e693bdacb74795b08271aca47d2fa91a (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function [romnum] = roman(num)
% ------------------------------------------------
% [romnum] = int2roman(num)
% Function converts a integer 2 a roman number (string)
% ------------------------------------------------
% output:
% num        ...roman number to be converted (number or string)
%

% author: Alexander Michel
% date: 2010/08/09
%
% Copyright 2010 Thomas König, Alexander Michel
%
% This file is part of NumericPlots.
%
% NumericPlots is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% any later version.
% 
% NumericPlots is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with NumericPlots.  If not, see <http://www.gnu.org/licenses/>.

if(isstr(num))
    numint = str2num(num);
else
    numint = num;
end
numint = round(numint);

rest = numint;
div = [1000 900 500 400 100 90 50 40 10 9 5 4 1];
letters = {'M','CM','D', 'CD','C','XC','L','XL','X','IX','V','IV','I'};
ii = 1;
while(rest~=0)
    z(ii) = floor(rest/div(ii));
    rest = mod(rest,div(ii));
    ii = ii+1;
end
romnum = '';

for(ii=1:length(z));
    for(jj=1:z(ii))
        romnum = [romnum letters{ii}];
    end
end

end