Adding time and date to table
70 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Benedikt Skurk
le 2 Mar 2021
Commenté : Benedikt Skurk
le 2 Mar 2021
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...
Réponse acceptée
Cris LaPierre
le 2 Mar 2021
Modifié(e) : Cris LaPierre
le 2 Mar 2021
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)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!