MATLAB: Proper reading of .txt

text scan read format

I would apreciate your contribution on the following:
I have several txt files (see attached 2 of them) correspong to weather stations (see Stations coordinates.txt), which I want to access and then do a number of things, eg. find mean values. The thing is, I cannot read them in the proper way using textscan. Of course the format I used ('%d %d %d') is all wrong but I can't find the correct one.
list1 = rdir ('C:\Projects\LIFE ASTI\C.3\C.3\Weather station data\from desktop\OutputObservations\');
obsdir = 'C:\Projects\LIFE ASTI\C.3\C.3\Weather station data\from desktop\OutputObservations\*.txt';
stations = readtable('C:\Projects\LIFE ASTI\C.3\C.3\Weather station data\from desktop\Stations coordinates.txt');
output_path='C:\Projects\LIFE ASTI\C.3\C.3\Weather station data\from desktop\OutputObservations';
% Variables
vars={'Temperature'; 'Relative humidity'};
years = {'2015'; '2019'};
varunits={'Celsius'; '%' };
%Starting loop for all files
for i=1:size(stations,1)
name = stations( i, 1 );
network = stations (i, 'Network');
lat = stations(i, 'Lat' );
lon = stations(i, 'Lon' );
%% Here we make the selection based on network and station
network.(1);
name.(1);
networkstr = char(network.(1));
namestr = char(name.(1));
indx = strfind (list1, namestr) ;
for j = 1:size(indx, 1)
if (indx{j,1}>0)
if (strfind (list1{j,1}, '2015') > 0)
if (strfind(list1{j,1}, 'txt') > 0)
disp(list1{j,1})
fileID = fopen(list1{j,1});
B = textscan(fileID,'%d %d %d');
fclose(fileID);
end
end
end
end
end

Best Answer

Just use readtable()? Looks like every station will have already-aggregated results (hourly vs daily for the same station, same year). You should be able to re-generated the daily data from the hourly data. If hourly is as fine-grained as you have, I would suggest using only those and working with timetables. readtable is smart enough and your dates are formatted well enough to be automatically imported as datetimes