Azzera filtri
Azzera filtri

Extract data from a csv file in Matlab

14 visualizzazioni (ultimi 30 giorni)
Katerina F
Katerina F il 28 Ott 2020
Risposto: Walter Roberson il 28 Ott 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 Commento
dpb
dpb il 28 Ott 2020
Use readtable instead...
Convert the time string to datetime

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 28 Ott 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.

Categorie

Scopri di più su Dates and Time 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!

Translated by