% FILE: roman.m
% PURPOSE: roman numeral representation (up to 100)
% EXAMPLE:
% x = roman(13);
function txt = roman(n)
if n >= 100, error('need to extend roman.m'); end
Is = rem(n,5);
Vs = rem((n-Is)/5,2);
Xs = rem((n-Is-5*Vs)/10,5);
Ls = rem((n-Is-5*Vs-10*Xs)/50,2);
txt='';
for i=1:Ls; txt = [txt 'L']; end
for i=1:Xs; txt = [txt 'X']; end
for i=1:Vs; txt = [txt 'V']; end
for i=1:Is; txt = [txt 'I']; end
x=strfind(txt, 'LXXXX');
if ~isempty(x); txt = [txt(1:x-1) 'CX' txt(x+5:end)]; end
x=strfind(txt, 'XXXX');
if ~isempty(x); txt = [txt(1:x-1) 'XL' txt(x+4:end)]; end
x=strfind(txt, 'VIIII');
if ~isempty(x); txt = [txt(1:x-1) 'IX' txt(x+5:end)]; end
x=strfind(txt, 'IIII');
if ~isempty(x); txt = [txt(1:x-1) 'IV' txt(x+4:end)]; end
end