1
votes

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 ? 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.

1

1 Answers

2
votes

Try this

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