Is there a function to do this?

답변 (3개)

Stephen23
Stephen23 2018년 1월 8일
편집: Stephen23 2018년 1월 8일

2 개 추천

There is no need to manipulate the format string, it is much simpler to use the '*' option:
>> sprintf('%0*d',4,12)
ans = 0012
Fangjun Jiang
Fangjun Jiang 2018년 1월 8일

0 개 추천

With this, will you be able to work out the function?
>> sprintf('%04d',12)
ans =
'0012'
Guillaume
Guillaume 2018년 1월 8일

0 개 추천

sprintf? Describing what you want in words would help
number = 12;
chars = 4;
formatstring = sprintf('%%0%dd', chars); %create format string %0{char}d' where {char} is the value of char
sprintf(formatstring, number)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2018년 1월 8일

편집:

2018년 1월 8일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by