MATLAB: How to convert date by changine date format from text file Dates and Timetext file I'd like to convert date according to first three column as day-month-year hour:minute:second. A column: Year B column: Day of the year C column: Hour I tried to do it, not achieving. Best Answer Simply, you can utilize table's functioinalities.t = readtable('test5.txt');% Create datetime and display as "day-month-year hour:minute:second" formatdt = datetime([t.Var1 ones(height(t), 1) t.Var2 t.Var3 zeros(height(t), 1) zeros(height(t), 1)], 'Format', 'dd-MM-yyyy HH:mm:ss');% Insert datetime variable to the table as "datestr" columnt.datestr = dt;% Write a table as a filewritetable(t, 'output.txt')UPDATEDBased on your comment, the following is what you want. removevars and movevars were introduced in R2018a.t = readtable('test5.txt');% Convert to datetimedt = datetime([t.Var1 ones(height(t), 1) t.Var2 t.Var3 zeros(height(t), 1) zeros(height(t), 1)]);% Insert datetime variables to original tablet.datestr = datetime(dt, 'Format', 'dd-MM-yyyy');t.timestr = datetime(dt, 'Format', 'HH:mm:ss');% Delete column 1 to 3T2 = removevars(t, 1:3);% Move datestr and timestr to the first and second columns T2 = movevars(T2, {'datestr', 'timestr'}, 'Before',1);% Write table as a tab separated file without headerswritetable(T2, 'output.txt', 'WriteVariableNames', false, 'Delimiter', 'tab') Related SolutionsMATLAB: How to convert date into day of the year You don't really need the hour of day.data=xlsread('Lat30.xlsx');date=datetime(data(:,1:3));d=day(date,'dayofyear'); MATLAB: Function for day of the year Introduced in R2014b>> day( datetime('07-Jan-2017', 'InputFormat', 'dd-MMM-yyyy' ), 'dayofyear' )ans = 7"accounting for leap years" If not, shame on The MathWorks!>> day( datetime('01-Mar-2017', 'InputFormat', 'dd-MMM-yyyy' ), 'dayofyear' )ans = 60>> day( datetime('01-Mar-2016', 'InputFormat', 'dd-MMM-yyyy' ), 'dayofyear' )ans = 61 Related QuestionHi, i have two dates like 2013_12_28 and 2014_01_06, and i want to calculate the mean date (2014_01_01) which would be in the form of 2014.0014How to convert three dimension daily data into monthly mean
Best Answer