Filter löschen
Filter löschen

Extract data from a csv file in Matlab

14 Ansichten (letzte 30 Tage)
Katerina F
Katerina F am 28 Okt. 2020
Beantwortet: Walter Roberson am 28 Okt. 2020
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 Kommentar
dpb
dpb am 28 Okt. 2020
Use readtable instead...
Convert the time string to datetime

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 28 Okt. 2020
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.

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by