Jos found a bug, which is caused by using "mn" as name of the variables for minutes and month. The bug has not been fixed for 8 weeks.
Although I appreciate that you write programs just for fun, the real fun for publishing functions in the FEX start, if the functions are working and if others can use them. Please update or remove this function.
Thanks.
Do no rely on this when you have to be on time ...
>> [d,t] = current_date
% d = 2009\11\25
% t =10:11:54
>> datestr(now)
ans = 25-Nov-2009 10:49:07
This trivial submission might have only some educational value, but than it should 1) work correctly; 2) have a lot of (edcucational) comments; and 3) a superior help section
Rounding the seconds is not correct: 59.6 sec should not be displayed as 60! Better use FIX.
Instead of NUM2STR and adding a leading '0', you can call SPRINTF('%.2d', hr) to get 2 digits. This can be combined:
full_date = clock;
date = sprintf('%.4d/%.2d/%.2d', full_date(1:3));
time = sprintf('%.2d:%.2d:%.2d', fix(full_date(4:6)));
Have you seen DATESTR?
24 Nov 2009
Write text file
write_txt_file - creates a .txt file with desired information as specified by "info_str)
Author: SamGhim
file = strcat(logpath,'\',filename)
can be improved:
file = fullfile(logpath, filename);
This considers a trailing file separator in the path and different separator for Unix and Windos.
if exist(file), fid = fopen(file,'at');
else, fid = fopen(file,'wt'); end
EXIST(Key) without specifying the type is very slow, because it tests for files, folders, variables, classes, ... Better use "exist(file, 'file')" -- but even better: omit the EXIST and use "fopen(file, 'at+')".