NUM2ORD Examples

The function NUM2ORD converts a numeric array to a string array of the rounded values with the corresponding ordinal suffixes, e.g.: 12 -> "12th".

Contents

1st Input: Numeric Array

NUM2ORD accepts any numeric array and returns a string array of exactly the same size:

num2ord([1,12,123,1234]) % vector
num2ord([1,12;123,1234]) % matrix
ans = 
  1×4 string array
    "1st"    "12th"    "123rd"    "1234th"
ans = 
  2×2 string array
    "1st"      "12th"  
    "123rd"    "1234th"

2nd Input: Suffix Only

The optional second input argument selects between returning both the values with suffixes (default) or just the suffixes by themselves:

num2ord(23,false) % default
num2ord(23,true)  % suffix only
ans = 
    "23rd"
ans = 
    "rd"

Correct Suffixes for Numbers Ending with 11, 12, or 13

Compare against IPTNUM2ORDINAL from the Image Processing Toolbox and also against NUM2ORDINAL from the Mapping Toolbox:

num2ord(111) % correct
num2ordinal(111) % wrong
iptnum2ordinal(111) % wrong
ans = 
    "111th"
ans =
    '111st'
ans =
    '111st'