How to remove date and time columns after merging as date_time?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Cakil
el 5 de Mayo de 2022
Comentada: Cakil
el 6 de Mayo de 2022
Hello,
I have a cell array of 24 datasets with almost 1 year time-series. I have date and time columns seperately. I merged them and created a date_time column.
I want to use the merged date_time column as my datetime column and remove the seperate date and time columns
dat_folder= % my directory
files = dir(fullfile(dat_folder,'*.dat'));
files = fullfile(dat_folder,{files.name});
n_files = numel(files);
table18 = cell(1,n_files);
for ii = 1:n_files
table18{ii} = readtimetable(files{ii});
end
for ii = 1:n_files % I have 24 files
table18{1,ii}.Day_Month_Year=table18{1,ii}.Day_Month_Year+years(2000)
table18{1,ii}.date_time=table18{1,ii}.Day_Month_Year+table18{1,ii}.Hour_Minute_Second
newtable18{1,ii} = table18{1,ii}(:,[6,2])
newtable18{1,ii}.date_time.Format='uuuu-MM-dd HH:mm:ss'
end
You can see the mat file in the attachment. I will glad to hear any comment!
Best,
Ezgi
0 comentarios
Respuesta aceptada
Stephen23
el 5 de Mayo de 2022
You can use REMOVEVARS:
Your code would be clearer if you use a temporary variable, e.g.:
for ii = 1:n_files
tmp = table18{ii};
tmp.Day_Month_Year = tmp.Day_Month_Year+years(2000);
tmp.date_time = tmp.Day_Month_Year+tmp.Hour_Minute_Second;
tmp = tmp(:,[6,2]); % ???
tmp.date_time.Format = 'uuuu-MM-dd HH:mm:ss';
tmp = removevars(tmp,{'Day_Month_Year','Hour_Minute_Second'});
table18{ii} = tmp;
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Time Series Events en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!