How do you add a 0 in front of single digit numbers in a numerical array?
46 次查看(过去 30 天)
显示 更早的评论
I later want to convert 2 numerical arrays into a string array and then back to a numerical array to combine a series of numbers. HOWEVER - to do this the numbers need to have the same amount of integers otherwise I get an empty matrix.
So my question is, how would I tell matlab to put a 0 in front a singular numbers in a 1x56 numerical array so all the numbers have the same amount of digits?
6 个评论
per isakson
2017-10-11
There is no such thing as leading zeros when it comes to numerical variables. Leading zeros in the string variable will vanish when "put that into a numerical".
Try to formulate your question/problem in other words.
回答(1 个)
Rik
2017-10-10
num2str, fprintf and sprintf all have options to specify a format when converting a numeric value to a string.
a=num2cell(1:10);
b=cellfun(@(x) sprintf('%02d',x),a,'UniformOutput',false);
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!