Adding date to timetable with just time
이전 댓글 표시
Hello,
I do have a timetable with just time in the first column, i would like to have the date too. I am able to get the date from the filename.
'03:08:48 PM' 4.67309300000000 23.2110000000000
'03:08:49 PM' 5.67272000000000 22.7290000000000
'03:08:50 PM' 6.67284700000000 22.2520000000000
'03:08:51 PM' 7.67297400000000 21.7820000000000
'03:08:52 PM' 8.67260100000000 21.3180000000000
'03:08:53 PM' 9.67322800000000 20.8370000000000
'03:08:54 PM' 10.6733600000000 20.3790000000000
'03:08:55 PM' 11.6729800000000 19.9230000000000
'03:08:56 PM' 12.6726100000000 19.4740000000000
'03:08:57 PM' 13.6727400000000 19.0420000000000
'03:08:58 PM' 14.6733600000000 18.6260000000000
'03:08:59 PM' 15.6729900000000 18.2250000000000
'03:09:00 PM' 16.6731200000000 17.8390000000000
'03:09:01 PM' 17.6727400000000 17.4660000000000
답변 (2개)
follow this
A=readtable('Book1.xlsx', 'PreserveVariableNames', 0);
AA=table2array(A);
B = regexp(AA, '\s+', 'split');
C = vertcat(B{:})
댓글 수: 12
Cristobal Gonzalez Diaz
2022년 2월 15일
Arif Hoq
2022년 2월 15일
A=readtable('Book2.xlsx', 'PreserveVariableNames', 0);
AA=table2array(A);
B = regexp(AA, '\s+', 'split');
C = vertcat(B{:});
t = datetime(now,'ConvertFrom','datenum','Format','dd-MM-yyyy HH:mm:ss a'); % today's Date
t1=cellstr(t);
splitDate = regexp(t1 , '\s+', 'split'); % split
D=vertcat(splitDate{:});
% D{1,1}=[];
add_data=[D(2:end) 5.234 23.456]; % data adding for today
synchonization=[C;add_data]; % add the today's data with previous data
Cristobal Gonzalez Diaz
2022년 2월 16일
A=readtable('20220214_Dep.txt');
DateStr = string({'2022-02-14';'2022-02-15'}) % make the date string
t = datetime(DateStr,'InputFormat','yyyy-MM-dd');
datevector=[repmat(t(1),size(A,1)-2,1); repmat(t(2),2,1)]; % adjust the date with your table
newTable = table(datevector, 'VariableNames',{'Date'}); % % Make a table with new Date
ExpectedTable = [ newTable,A] % concatenate the new Date table with main Table
Arif Hoq
2022년 2월 17일
if you want export your data..
writetable(ExpectedTable,'Book2.xlsx','Sheet',1) % if you want to write your table to excel
writetable(ExpectedTable,'Book1.txt','Delimiter','tab') % if you want to write your table to text file
Cristobal Gonzalez Diaz
2022년 2월 17일
t = datetime(now,'ConvertFrom','datenum','Format','dd-MM-yyyy HH:mm:ss a'); % today's Date
You don't need to use now if you want to know today's date (with the time portion representing midnight.)
t = datetime('today')
t.Format = 'dd-MM-yyyy hh:mm:ss a'
So what's 16 hours 23 minutes after midnight?
t2A = t + hours(16) + minutes(23) % or
t2B = t + duration(16, 23, 0)
Cristobal Gonzalez Diaz
2022년 2월 18일
Cristobal Gonzalez Diaz
2022년 2월 24일
편집: Cristobal Gonzalez Diaz
2022년 3월 2일
Arif Hoq
2022년 2월 25일
so, did you get your solution ?
Cristobal Gonzalez Diaz
2022년 2월 28일
Walter Roberson
2022년 3월 2일
year = str2double(filename(1:4));
month = str2double(filename(5:6));
day = str2double(filename(7:8));
basedt = datetime(year, month, day, 'Format', 'd-M-yyyy HH:mm:ss');
AA.TimePC = basedt + AppropriateDurationVariable;
Cristobal Gonzalez Diaz
2022년 3월 3일
댓글 수: 2
Walter Roberson
2022년 3월 3일
The logic is a bit weak. As outside observers we would question whether it is guaranteed that there are no skipped days. For example if no data was collected for February 17th because of a storm, then the files might go from 16th to 18th, but your code assumes each 00:00:00 is exactly one day after the previous.
Cristobal Gonzalez Diaz
2022년 3월 3일
카테고리
도움말 센터 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!