Format numbers in vector with leading zero: 1 -> 01
32 ビュー (過去 30 日間)
古いコメントを表示
Is there a way to format a number in Matlab with leading zero?
Suppose I have a number 1, so it would be 01. I need to obtain a number representation of some strings with letters converted into numbers with leading zeros.
0 件のコメント
回答 (1 件)
the cyclist
2016 年 5 月 17 日
sprintf('%02d',1)
3 件のコメント
the cyclist
2016 年 5 月 17 日
Despite the name, it is not "just printing". It is creating a variable that is the string. You can combine them however you want. For example
s1 = [sprintf('%02d',1),sprintf('%02d',7)]
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!