Convert array of numbers to an array of padded strings
조회 수: 3 (최근 30일)
이전 댓글 표시
I have an array of numbers to convert to an array of strings.
>> stanums = 7:12;
>> stastrings = string( stanums );
stanums =
7 8 9 10 11 12
stastrings =
"7" "8" "9" "10" "11" "12"
How can I have the strings zero-padded? ie "07" "08" etc.
I tried with num2str, but can only manage that using a loop, and I would really like a more elegant way as my code has far too many loops in it already.
댓글 수: 0
답변 (2개)
Star Strider
2023년 9월 27일
stanums = 7:12;
stastrings = compose("%02d", stanums)
Note the format descriptor string.
.
댓글 수: 0
참고 항목
카테고리
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!