Numeric to Ordinal-String

版本 2.2.1 (5.5 KB) 作者: Stephen23
Convert numeric values to a string array of integers with ordinal suffixes. Fully vectorized!
868.0 次下载
更新时间 2024/2/3

查看许可证

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).
Examples
>> 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"]

引用格式

Stephen23 (2024). Numeric to Ordinal-String (https://www.mathworks.com/matlabcentral/fileexchange/42833-numeric-to-ordinal-string), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2010b
与 R2017a 及更高版本兼容
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
2.2.1

* Add more floating point testcases.

2.2.0

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

2.1.3

* Add testcases.

2.1.2

* Update description.

2.1.1

* Update description.

2.1.0

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

2.0.4

* Minor edits to Mfile help.

2.0.3

* Include test function.
* Improve examples.

2.0.2

* Correct sreenshot

2.0.1

* Correct screenshot.

2.0.0

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

1.5.2

* Add error IDs.

1.5.1

* Added HTML documentation. Function unchanged.

1.5.0.0

* Improve documentation.

1.4.0.0

Added Acknowledgements

1.3.0.0

- Fix minor bug with int* and uint*.

1.2.0.0

- Improve function description, add acknowledgements.

1.1.0.0

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

1.0.0.0