Skip to content

int2str

Converting an array of integers to a character array

int2str(A)

  • A should be an array of integer values.
  • It returns a character array by converting entries of A to characters.
  • For example, if A is [1 2], the output would be the character array '1 2'.
  • If A contains non-integer values, they are rounded to integers.
  • If A is multi-dimensional, it is first reshaped to a matrix (i.e., 2D array) having the same number of rows.
  • If A is a character array, the output is the same as A.
  • If A is empty, it returns an empty array.

Example 1: A multi-dimensional array is first reshaped before being converted to a character array.

a=randi(10,3,3,3)
int2str(a)
a(:, :, 1) = 

 6.000   4.000   2.000
 10.00   8.000   4.000
 1.000   7.000   9.000

a(:, :, 2) = 

 6.000   5.000   3.000
 9.000   8.000   5.000
 6.000   5.000   1.000

a(:, :, 3) = 

 10.00   8.000   1.000
 9.000   10.00   2.000
 1.000   3.000   7.000

ans =
6  4 2 6 5 3 10 8  1
10 8 4 9 8 5 9  10 2
1  7 9 6 5 1 1  3  7