How do I fix Invalid use of operator in the Code

조회 수: 1 (최근 30일)
MBUNYA NERVILLE ANYANG
MBUNYA NERVILLE ANYANG 2023년 5월 24일
댓글: MBUNYA NERVILLE ANYANG 2023년 5월 24일
I want to create a datetime table from excel having date and time in two separate columns.
T = readtable('LP.xlsx');
Col2 = datetime(str2double(T{:,2}), 'ConvertFrom','excel', 'Format','HH:mm:ss'); % Dates
Col1 = datetime(str2double({:,1}),'ConvertFrom','excel', 'Format','dd/MM/yyyy'); % Times
Invalid use of operator.
DT = table(Col1+timeofday(Col2), 'VariableNames',{'DateTime'}); % Combined
T = [DT T(:,3:end)]; % New Table
FirstFiveRows = T(1:5,:)
Error using datetime
Invalid parameter name: ConverFrom.
Please How do I merge column 1(Date) and column 2(Time) to one column having datetime? Thanks

채택된 답변

Stephen23
Stephen23 2023년 5월 24일
편집: Stephen23 2023년 5월 24일
T = readtable('LP.xlsx')
T = 240×3 table
Date Time T _____ ________ ____ 39083 0 22.7 39083 0.041667 22.5 39083 0.083333 22 39083 0.125 21.8 39083 0.16667 21.6 39083 0.20833 21.7 39083 0.25 22.2 39083 0.29167 23.6 39083 0.33333 25 39083 0.375 26 39083 0.41667 27 39083 0.45833 27.6 39083 0.5 27.6 39083 0.54167 27.5 39083 0.58333 27.2 39083 0.625 26.6
T.DT = datetime(T.Date, 'ConvertFrom','excel') + days(T.Time)
T = 240×4 table
Date Time T DT _____ ________ ____ ____________________ 39083 0 22.7 01-Jan-2007 00:00:00 39083 0.041667 22.5 01-Jan-2007 01:00:00 39083 0.083333 22 01-Jan-2007 02:00:00 39083 0.125 21.8 01-Jan-2007 03:00:00 39083 0.16667 21.6 01-Jan-2007 04:00:00 39083 0.20833 21.7 01-Jan-2007 05:00:00 39083 0.25 22.2 01-Jan-2007 06:00:00 39083 0.29167 23.6 01-Jan-2007 07:00:00 39083 0.33333 25 01-Jan-2007 08:00:00 39083 0.375 26 01-Jan-2007 09:00:00 39083 0.41667 27 01-Jan-2007 10:00:00 39083 0.45833 27.6 01-Jan-2007 11:00:00 39083 0.5 27.6 01-Jan-2007 12:00:00 39083 0.54167 27.5 01-Jan-2007 13:00:00 39083 0.58333 27.2 01-Jan-2007 14:00:00 39083 0.625 26.6 01-Jan-2007 15:00:00

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by