Programming and Data Types    

Numeric/String Conversion

The MATLAB string/numeric conversion functions change numeric values into character strings. You can store numeric values as digit-by-digit string representations, or convert a value into a hexadecimal or binary string. Consider a the scalar

By default, MATLAB stores the number x as a 1-by-1 double array containing the value 5317. The int2str (integer to string) function breaks this scalar into a 1-by-4 vector containing the string '5317'.

A related function, num2str, provides more control over the format of the output string. An optional second argument sets the number of digits in the output string, or specifies an actual format.

Both int2str and num2str are handy for labeling plots. For example, the following lines use num2str to prepare automated labels for the x-axis of a plot.

Another class of numeric/string conversion functions changes numeric values into strings representing a decimal value in another base, such as binary or hexadecimal representation. For example, the dec2hex function converts a decimal value into the corresponding hexadecimal string.

See the strfun directory for a complete listing of string conversion functions.

  Searching with Tokens Array/String Conversion