How to convert a vector of integers to a vector of characters?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
James Tursa
le 10 Fév 2013
Another method for single digits:
A = [0 0 0 0 1 0 0 0 0 1];
B = char(A+'0');
0 commentaires
Plus de réponses (3)
Wayne King
le 9 Fév 2013
Modifié(e) : Wayne King
le 9 Fév 2013
A = [0 0 0 0 1 0 0 0 0 1];
B = num2str(A);
Now B is a vector of characters
2 commentaires
Azzi Abdelmalek
le 9 Fév 2013
Modifié(e) : Azzi Abdelmalek
le 9 Fév 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
0 commentaires
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!