简体   繁体   English

Matlab fprintf的打印日期

[英]Matlab fprintf printing date

I'm trying to print the hour in a file using fprintf, hr, minute,sec being computed from a Julian date and I was wondering if there was an elegant way to tell matlab that if the value was smaller than 10 it should put a 0 before it ? 我正在尝试使用从儒略日期计算得出的fprintf,hr,min,sec在文件中打印小时,我想知道是否有一种优雅的方法来告诉matlab,如果值小于10,则应该放一个0之前呢? I get this kind of output : 我得到这种输出:

14: 0: 3.000
 5:11: 3.000 

using this code 使用此代码

fprintf(outfile,...
        '%2i:%2i:%6.3f',hr,minute,sec);

EDIT : I thought about if loops and this is what I'm heading to, but I'm wondering if there is any more elegant way to do it. 编辑:我考虑过if循环,这就是我要去的方向,但是我想知道是否还有任何更优雅的方法可以做到这一点。

Try this 尝试这个

>> fprintf('%02i:%02i:%06.3f\n', 6, 5, 7.123);
06:05:07.123

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM