필터 지우기
필터 지우기

How to remove date and time columns after merging as date_time?

조회 수: 3 (최근 30일)
Cakil
Cakil 2022년 5월 5일
댓글: Cakil 2022년 5월 6일
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

채택된 답변

Stephen23
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
  댓글 수: 1
Cakil
Cakil 2022년 5월 6일
Thank you it is working. I am new to Matlab so my scripts are not very clean yet.
The only thing is I am converting timetable to table to remove the variable and then converting to the the timetable again.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by