Function Description Example
dec2base Convert a positive integer to a character type of any
base from 2 through 36.
[72 105] → '110
151' (base set to 8 )
Convert Numbers to Character Codes
The char function converts integers to Unicode character codes and returns a character
array composed of the equivalent characters:
x = [77 65 84 76 65 66];
char(x)
ans =
'MATLAB'
Represent Numbers as Text
The int2str, num2str, and mat2str functions represent numeric values as text where
each character represents a separate digit of the input value. The int2str and num2str
functions are often useful for labeling plots. For example, the following lines use num2str
to prepare automated labels for the x-axis of a plot:
function plotlabel(x, y)
plot(x, y)
chr1 = num2str(min(x));
chr2 = num2str(max(x));
out = ['Value of f from ' chr1 ' to ' chr2];
xlabel(out);
Convert to Specific Radix
Another class of conversion functions changes numeric values into character arrays
representing a decimal value in another base, such as binary or hexadecimal
representation. This includes dec2hex, dec2bin, and dec2base.
6 Characters and Strings