Numeric to Ordinal-String

Version 2.2.1 (5,46 ko) par Stephen23
Convert numeric values to a string array of integers with ordinal suffixes. Fully vectorized!
864 téléchargements
Mise à jour 3 fév. 2024

Afficher la licence

Convert a numeric array into a string array of the rounded values with ordinal suffixes, e.g. 1 => "1st".
Similar to MATLAB's IPTNUM2ORDINAL (image toolbox) and NUM2ORDINAL (mapping toolbox) and other files available on FEX, except that NUM2ORD:
  • accepts a numeric array of any size,
  • accepts a numeric array of any class (floating point, INTx or UINTx),
  • returns a string array (not a character array!),
  • is fully vectorized (no loops or ARRAYFUN calls are used or required),
  • provides the correct ordinal suffixes for numeric values ending in 11, 12, or 13.
Character Output
For MATLAB versions prior to R2017a please download version 1.5.2 (with character array output).
>> num2ord(1)
ans = "1st"
>> num2ord(1:6)
ans = ["1st","2nd","3rd","4th","5th","6th"]
>> [str,sfx] = num2ord([1;11;111;1111])
str = ["1st";"11th";"111th";"1111th"]
sfx = [ "st"; "th"; "th"; "th"]
>> num2ord(intmax('int64')-4)
ans = "9223372036854775803rd"
>> num2ord([-1,-0,0;-Inf,NaN,Inf])
ans = ["-1th","-0th","0th";"-Infth","NaNth","Infth"]

Citation pour cette source

Stephen23 (2024). Numeric to Ordinal-String (, MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2010b
Compatible avec les versions R2017a et ultérieures
Plateformes compatibles
Windows macOS Linux
En savoir plus sur Characters and Strings dans Help Center et MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Publié le Notes de version

* Add more floating point testcases.


* Add 2nd output, with just the suffixes.
* Remove the optional 2nd input.


* Add testcases.


* Update description.


* Update description.


* Add test cases.
* More robust input class handling.


* Minor edits to Mfile help.


* Include test function.
* Improve examples.


* Correct sreenshot


* Correct screenshot.


* Change to string array output.
* Rename function NUM2ORDINAL -> NUM2ORD.


* Add error IDs.


* Added HTML documentation. Function unchanged.

* Improve documentation.

Added Acknowledgements

- Fix minor bug with int* and uint*.

- Improve function description, add acknowledgements.

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