フィルターのクリア

Extract data from a csv file in Matlab

14 ビュー (過去 30 日間)
Katerina F
Katerina F 2020 年 10 月 28 日
回答済み: Walter Roberson 2020 年 10 月 28 日
Hello,
I am trying to open csv file in Matlab (2020) and extract the data, then put the first column of the data in three columns, year, month day hour.
The data in the csv file attached.
I am using the code below but it is not working. It extracts columns with NaN values. Could you please help me with this? Thanks
fileID = fopen('AberSARAHsolar30deg0deg2012.csv','rt')
C=textscan(fileID,'%s %s %s %s %s %s %s %s ','delimiter',',');
fclose(fileID)
%EXTRACT
time =C{1}(2:end);
Gizero = str2double(C{2}(2:end));
T2m=str2double(C{4}(2:end));
WS10m = str2double(C{5}(2:end));
Githirty =str2double(C{8}(2:end));
%EXTRACT TEXT TO YEAR MONTH DAY HOUR
formatIn ='yyyy-mm-dd hh';
DATETIME=datevec(time,formatIn);
YMDH=DATETIME(:,1:4);
  1 件のコメント
dpb
dpb 2020 年 10 月 28 日
Use readtable instead...
Convert the time string to datetime

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

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 10 月 28 日
formatIn ='yyyymmdd:HHMM';
It is questionable as to whether that is the correct format, however. Each of the entries ends in 11 . It is not impossible that each of them was taken at exactly 11 minutes after each hour, but it would be uncommon.

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by