Thanks for the help!! appreciate it !
Adding time and date to table
조회 수: 54 (최근 30일)
이전 댓글 표시
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...
채택된 답변
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!