image thumbnail

Numeric to Ordinal-String

version 2.1.3 (5.2 KB) by Stephen
Convert numeric values to a string array of integers with ordinal suffixes. Fully vectorized!

798 Downloads

更新31 Jan 2022

View License

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 class (float, int or uint),
  • 返回字符串数组(不是字符数组!),
  • 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.
The optional second input selects between returning the integer and ordinal suffix (default), or just the ordinal suffix by itself.
Character Output
对于R2017A之前的MATLAB版本,请下载1.5.2版(带有字符数组输出)。
Examples
>> num2ord(1)
ans ="1st"
>> num2ord(1:6)
ans = ["1st","2nd",“第三”,"4th","5th","6th"]
>> num2ord([1;11;111;1111])
ans = ["1st";“第11”;“第111”;“ 1111”]
>> num2ord(100:113,true)
ans = ["th","st",“ nd”,"rd","th","th","th","th","th","th","th","th","th","th"]
>> num2ord(intmax('int64')-4)
ans ="9223372036854775803rd"
>> num2ord([ - 1,-0,0; ​​-inf,nan,inf])
ans = [“ -1”,"-0th","0th";“ -infth”,"NaNth","Infth"]

Cite As

斯蒂芬(2022)。Numeric to Ordinal-String(//www.tatmou.com/matlabcentral/fileexchange/42833-numeric-to-ordinal-string), MATLAB Central File Exchange. Retrieved.

MATLAB释放兼容性
Created with R2010b
Compatible with R2017a and later releases
Platform Compatibility
视窗 macOS Linux

Community Treasure Hunt

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

开始狩猎!