# How to convert a vector of integers to a vector of characters?

27 views (last 30 days)
Michael on 9 Feb 2013
Hi - I have a vector of ints, typically 0/1, like this:
[0 0 0 0 1 0 0 0 0 1]
and I want to get this:
['0' '0' '0' '0' '1' '0' '0' '0' '0' '1']
But I cannot figure it out for the life of me. I'm sure it's simple. Thanks for your time and help.

James Tursa on 10 Feb 2013
Another method for single digits:
A = [0 0 0 0 1 0 0 0 0 1];
B = char(A+'0');

Wayne King on 9 Feb 2013
Edited: Wayne King on 9 Feb 2013
A = [0 0 0 0 1 0 0 0 0 1];
B = num2str(A);
Now B is a vector of characters
##### 2 CommentsShowHide 1 older comment
Wayne King on 9 Feb 2013

Azzi Abdelmalek on 9 Feb 2013
Edited: Azzi Abdelmalek on 9 Feb 2013
a = [0 0 0 0 1 0 0 0 0 1];
y=arrayfun(@(x) cellstr(num2str(x)),a)
% To get any character
y{4} % for e.g

Jan on 10 Feb 2013
Edited: Jan on 10 Feb 2013
Instead of removing the spaces from the output of num2str, you can create string without spaces directly:
a = [0 0 0 0 1 0 0 0 0 1];
s = sprintf('%d', a);
Another fast but more strange method is:
s = char('0' + a);