フィルターのクリア

Wrong date while importing .csv

3 ビュー (過去 30 日間)
Ancalagon8
Ancalagon8 2018 年 8 月 24 日
コメント済み: Ancalagon8 2018 年 9 月 3 日
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?
  5 件のコメント
Stephen23
Stephen23 2018 年 8 月 24 日
編集済み: Stephen23 2018 年 8 月 24 日
@Sirius8: this is what one line of the file looks like:
00:00:0;0.0;0.00540500736377
Where is the date? Please show us which parts of that line contain date data.
Ancalagon8
Ancalagon8 2018 年 8 月 24 日
You are right. The date was not in the data but in the name of the csv

サインインしてコメントする。

採用された回答

jonas
jonas 2018 年 8 月 24 日
編集済み: jonas 2018 年 8 月 24 日
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 件のコメント
jonas
jonas 2018 年 8 月 24 日
編集済み: jonas 2018 年 8 月 24 日
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!!
Ancalagon8
Ancalagon8 2018 年 9 月 3 日
In general it works. At some daily files i get this error in the line "tday=cell2mat(tday);"
"Error in cell2mat (line 83) m{n} = cat(1,c{:,n});"
files=dir('*2018-08-25.csv');
for i=1:length({files.name})
date=files(i).name;
date=regexprep(date,'.csv','');
din=importdata(files(i).name,';');
tday=cellfun(@(x) str2double(strsplit(x,':')),din.textdata,'uniformoutput',false);
tday=cell2mat(tday);
ti=hours(tday(:,1))+minutes(tday(:,2))+seconds(tday(:,3))+datetime(date);
xyi=din.data;
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by