Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Numeric to Ordinal-String

Be the first to rate this file! 11 Downloads (last 30 days) File Size: 2.24 KB File ID: #42833 Version: 1.4
image thumbnail

Numeric to Ordinal-String



25 Jul 2013 (Updated )

Convert numeric values to a character array of integers with ordinal suffixes (numeric -> string).

| Watch this File

File Information

### Why This Function? ###
Convert a numeric scalar/vector/matrix/array to a character array giving the integers and ordinal suffixes of the rounded input element values, eg. 1 -> '1st', 2 -> '2nd'.

Similar to MATLAB's "iptnum2ordinal" and other files available on FEX, except that this function accepts numeric arrays (not just scalars) of any class (float, int* or uint*) and is fully vectorized (no loops or "arrayfun" calls are used or required). The function rounds fractional numeric values to the nearest integer, and provides the correct suffixes for numeric values ending in 11, 12 or 13. The optional second input selects between returning the integer and suffix (default), or just the suffix (fast!).

### Examples ###

 ans = '1st'

 ans = ['1st';'2nd';'3rd';'4th';'5th';'6th']

 ans = [' 1st';' 11th';' 111th';'1111th']

 ans = ['th';'st';'nd';'rd';'th';'th';'th';'th';'th';'th';'th';'th';'th';'th']

 ans = '9223372036854775803rd'

 ans = ['-0th';' 0th']

vals = [-1,-0,0;-Inf,NaN,Inf];
 ans = {'-1th','-0th','0th';'-Infth','NaNth','Infth'}

### Note ###

Compared to MATLAB standard functions and several M-files available on MATLAB File Exchange, this file:
- Correctly converts all numeric values ending in 11, 12, or 13.
- Accepts a scalar/array numeric.
- Is fully vectorized.
- Optionally returns only the ordinal suffix (fast!).
- Returns the complete digits for "uint*" and "int*" type numerics.
- Distinguishes between positive and negative zero.


Number To Ordinal String Converter and Ordnumstr inspired this file.

This file inspired Regular Expression Helper, Number To Myriad, Number To Words, and Words To Number.

Required Products MATLAB
MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
17 Mar 2014 1.1

- Fix minor bugs with -0, int* & uint* handling.

15 Apr 2014 1.2

- Improve function description, add acknowledgements.

15 Apr 2014 1.3

- Fix minor bug with int* and uint*.

18 Apr 2014 1.4

Added Acknowledgements

Contact us