How to remove date and time columns after merging as date_time?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Stephen23
2022-5-5
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Time Series Events 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!