How to add dates to a read loop

조회 수: 1 (최근 30일)
Ioannis Tsikriteas
Ioannis Tsikriteas 2017년 9월 8일
답변: Peter Perkins 2017년 9월 14일
hi, i have the following loop which reads a lot xls files and stores them in a table. Each file contains hourly data at a specific date starts from 01/01/2012
myFolder = 'C:\Users\...\All';
filePattern = fullfile(myFolder, '*.xls');
theFiles = dir(filePattern);
x={ };
for k = 1 : length(theFiles) ;
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
x{k} = readtable(fullFileName);
end
How can i add an extra column to each table with the date of each file from which the table was created?
For example the third file contains 24 records of the date 03/01/2012

답변 (2개)

Jose Marques
Jose Marques 2017년 9월 9일
  댓글 수: 1
Ioannis Tsikriteas
Ioannis Tsikriteas 2017년 9월 9일
Sorry but i have read the above answer you suggested and this refers to today dates! Mine are dates of the past, from 01/01/2012 until 31/12/2016 and i want each one of these dates to be added to the table (or timetable to be exact) for each {k} of the loop.
For example, {k}=3 is the date 03/01/2012, {k}=445 is the date 30/03/2013
The total length of the files are 1925

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


Peter Perkins
Peter Perkins 2017년 9월 14일
Create a datetime column vector and assign it to your table.
d = datetime(2012,3,repmat(1,24,1)) % assuming you mean march 1st, not jan 3rd x{k}.Time = d;

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by