by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 1.0, Creation date: 2012-12-11, Last change: 2025-09-14
See Also: roman
, datestrroman
[S,nL]=roman(n)
n: | number |
S: | String of roman number | |
nL: | separated divisor list |
roman (2012)
This algorithm converts an integer into its Roman numeral representation. It is implemented in a MATLAB function named roman. The function takes a single input parameter and returns two outputs.
S to build the Roman numeral.n using floor(n/1000) and append 'M' that many times to S. Subtract the equivalent value from n.n is 900 or more, append 'CM' to S and subtract 900 from n.n using floor(n/500) and append 'D' that many times to S. Subtract the equivalent value from n.n is 400 or more, append 'CD' to S and subtract 400 from n.n using floor(n/100) and append 'C' that many times to S. Subtract the equivalent value from n.n is 90 or more, append 'XC' to S and subtract 90 from n.n using floor(n/50) and append 'L' that many times to S. Subtract the equivalent value from n.n is 40 or more, append 'XL' to S and subtract 40 from n.n using floor(n/10) and append 'X' that many times to S. Subtract the equivalent value from n.n is 9, append 'IX' to S and set n to 0.n using floor(n/5) and append 'V' that many times to S. Subtract the equivalent value from n.n is 3 or less, append 'I' that many times to S. Otherwise, append 'IV' to S.nL containing the counts of each Roman numeral symbol used: [M, D, C, L, X, V, n].