开发者

print 0's before a variable

I know in c, c++, and all other kinds of programming code you can use the syntax "%4d" to print a total of 4 digits. If the variable is only one digit, it will print three 0's and whatever your variable is, if your variable is 2 digits, two 0's and so on. However in Octave it seems that it will print out spaces instead of 0's. Is there a way to force it to print out zeros but keep the specified length of 4 integers?

This is for naming files that the program is outputting so the leading zero's are needed to hel开发者_运维问答p organize the data that is outputted.


The place to look is the Matlab documentation: http://www.mathworks.co.uk/help/techdoc/ref/sprintf.html.

But the answer is something like:

sprintf('%04d', 42);  % Prints "0042"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜