NUM2STR2 convers numbers to strings. Contrary to the Matlab routine NUM2STR, this utility makes it possible to specify the number of characters for the string representation.
T = num2str2(X,C)
returns a string T with C characters. In general, the number of decimal places will be equal to C - 2 (= number of characters minus space reserved for possible signs or decimal points). If a number does not fit, it is rounded to a value which does fit in C characters. If the number of characters is not specified, as in: T = NUM2STR2(X)
, the return-string T will automatically be set-up with 6 characters. Leading spaces will be used for numbers requiring less than C characters.
If necessary, an exponent will be created, still within the reserved space of C characters. In that case the number of decimal places will be reduced (an exponent typically takes four characters, e.g. 'E+25').
Note: values of C smaller than 6 are not accepted and automatically converted to C = 6! This prevents problems that may occur when trying to show very large numbers in too few characters. However, you may still encounter strange results if you reserve a very small space for large numbers.