Borrar filtros
Borrar filtros

Extract data from a csv file in Matlab

14 visualizaciones (últimos 30 días)
Katerina F
Katerina F el 28 de Oct. de 2020
Respondida: Walter Roberson el 28 de Oct. de 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 comentario
dpb
dpb el 28 de Oct. de 2020
Use readtable instead...
Convert the time string to datetime

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 28 de Oct. de 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.

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by