| Description |
### Function ###
A "natural order" sort is where any numeric values occuring within the strings is taken into account in the sort. Compare for example:
A = {'File2.txt','File10.txt','File1.txt'};
sort(A)
ans = {'File1.txt','File10.txt','File2.txt'}
sortnat(A)
ans = {'File1.txt','File2.txt','File10.txt'}
# This function provides optional user-control over the numeric value format, allowing plus/minus signs, decimal points, exponents, etc., to be taken into account in the numeric values.
# This function is faster than other "natural order" Mfiles provided on MATLAB File Exchange.
### Examples ###
# The default is for integer values only, as shown above.
# Integer or decimal numeric tokens, possibly with +/- signs:
B = {'File102.txt','File11.5.txt','File-1.4.txt','File+0.3.txt'};
sort(B)
ans = {'File+0.3.txt','File-1.4.txt','File102.txt','File11.5.txt'}
sortnat(B,'(-|+)?\d+(\.\d+)?')
ans = {'File-1.4.txt','File+0.3.txt','File11.5.txt','File102.txt'}
# Integer or decimal numeric tokens, possibly with an exponent:
C = {'A_0.56e+07','A_4.3E2','A_10000','A_9.8'};
sort(C)
ans = {A_'0.56e+07','A_10000','A_4.3E2','A_9.8'}
sortnat(C,'\d+(\.\d+)?(e(+|-)?\d+)?')
ans = {'A_9.8','A_4.3E2','A_10000','A_0.56e+07'}
# ASCII order (including non-printing characters):
sortnat(CellStr,'[]',true); |