Adding time and date to table

조회 수: 54 (최근 30일)
Benedikt Skurk
Benedikt Skurk 2021년 3월 2일
댓글: Benedikt Skurk 2021년 3월 2일
Hi i want to read a csv file and add in the first column from row 3 to end a date and time vector which i generate with the following code
ElmLnecloading = readtable('ElmLne_c_loading.csv');
t1 = datetime(2017,1,1,0,15,0);
t2 = datetime(2017,12,31,23,45,0);
interval = minutes(15);
Vector = (t1:interval:t2);
DateString = char(Vector');
disp(DateString)
ElmLnecloading(3:end,1) = DateString;
disp(ElmLnecloading)
but i always get the following error:
To assign to or create a variable in a table, the number of rows must match the height of the table.
A picture of a part of the file is attached. It has 35041 rows
Can someone help me how to solve the problem or having an easier way to solve my problem? I am pretty new to Matlab...
  댓글 수: 1
Benedikt Skurk
Benedikt Skurk 2021년 3월 2일
Thanks for the help!! appreciate it !

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

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 3월 2일
편집: Cris LaPierre 2021년 3월 2일
In MATLAB, all elements of one table variable should be of the same data type. For this reason, I suspect your table in MATLAB has removed the first 2 rows. This means (3:end,1) is actually 2 rows shorter than DateString, resulting in the size mismatch error.
Tables allow you to have variables of different datatypes in the same table. I would therefore recommend keeping your dates as datetimes.
t1 = datetime(2017,1,1,0,15,0);
t2 = datetime(2017,12,31,23,45,0);
interval = minutes(15);
Vector = (t1:interval:t2)';
data = rand(length(Vector),1);
dTbl = table(Vector,data)
dTbl = 35039x2 table
Vector data ____________________ _______ 01-Jan-2017 00:15:00 0.13599 01-Jan-2017 00:30:00 0.90735 01-Jan-2017 00:45:00 0.9517 01-Jan-2017 01:00:00 0.63316 01-Jan-2017 01:15:00 0.40791 01-Jan-2017 01:30:00 0.31211 01-Jan-2017 01:45:00 0.97797 01-Jan-2017 02:00:00 0.46379 01-Jan-2017 02:15:00 0.28019 01-Jan-2017 02:30:00 0.10032 01-Jan-2017 02:45:00 0.51595 01-Jan-2017 03:00:00 0.64312 01-Jan-2017 03:15:00 0.87067 01-Jan-2017 03:30:00 0.98085 01-Jan-2017 03:45:00 0.61279 01-Jan-2017 04:00:00 0.65733
  댓글 수: 1
Benedikt Skurk
Benedikt Skurk 2021년 3월 2일
Thanks for the help! appreciate it !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by