Wrong date while importing .csv
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Having a problem when i import daily .csv files. More specifically, when i plot my xy data(x axis contains date and time stamp), in every different daily file, MATLAB shows todays date. Any ideas?
Risposta accettata
jonas
il 24 Ago 2018
Modificato: jonas
il 24 Ago 2018
The date is not automatically assigned because it's not in the data but in the name of the file. You could do something like this:
files=dir('folderpath~\*.csv');
for i=1:length({files.name})
date=files(i).name;
date=regexprep(date,'.csv','')
data=readtable(files(i).name);
t{i}=data{:,1}+datetime(date);
xy{i}=data{:,2:3}
end
Now you have two cell arrays, t and xy, where the former has all time data and the latter all other data.
18 Commenti
jonas
il 24 Ago 2018
Modificato: jonas
il 24 Ago 2018
You're welcome! Note that you can just remove the curly braces from the t{i} if you want to achieve that. I put the results in a cell array as I figured you have several data sets that you want to load and store.
Also, don't use datetime as a variable name!!
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!