The issue here is the use of "datetime" function to store time values. As the name of the function suggests, it takes both the date and time into account when it returns the output "time" in the question above. Since the input does not specify any date specifically, "datetime" function uses the current date as the date component of the output which explains why the data written to Excel is based on the day, the data is being written to Excel.
Since the input data corresponds to only time and not date, the correct function to use in this context is "duration" which represents elapsed times in units of fixed length, such as hours, minutes, and seconds. Using the "duration" function instead of "datetime" results in the data being written to Excel in the desired form:
>> time = duration({'03:05:12';'04:05:12';'05:05:12'},'Format','hh:mm:ss');
>> data = [1; 2; 3];
>> T = table(time,data);
>>
>> writetable(T, 'Book1.xlsx');
Here is the documentation for "duration" for your reference:
Best Answer