How do I vectorize each digit of an integer and store it as an array?
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Srishti Saha
am 8 Mai 2018
Bearbeitet: Stephen23
am 8 Mai 2018
I have to convert an integer into a vector of all its digits. Example: 100---> [1 0 0]
function ans = int2vec(x)
t=regexp(num2str(x),'\d','match');
[];
arrayfun(@(i) [ans,str2num(t{i})],1:length(t));
end
Though this worked for me, is there a better solution.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!