-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollectMaxPrecipPointsForAStation.m
35 lines (35 loc) · 1.34 KB
/
CollectMaxPrecipPointsForAStation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
%this program is the function of CollectMaxPrecipPointsForAStation for
%Precipitation
%Use this to verify the program
function MaxPoints = CollectMaxPrecipPointsForAStation(folder)
%Define the folder location of CSV files
i=1; %Set i=1 so that it does not give error for data{0} which is impossible
%use the Datastore function to read all the CSV files in the folder
ds = tabularTextDatastore(folder,'FileExtensions','.csv','SelectedVariableNames',{'Date_Time','TotalPrecip_mm_'});
%a while loop divides the Datastore variable data into years
while hasdata(ds)
data{i} = read(ds);
i=i+1;
end
%traspose the cells in data cell
for k=1:numel(data)
data2{k,1} = data{1,k};
end
%Extract maximum data points for each of the years
u = numel(data);
for k=1:u
A = (data2{k,1});
temp_A_Date_Time = datetime(A.Date_Time,'InputFormat','yyyy-MM-dd');
A.Date_Time = temp_A_Date_Time;
Precip = cell2table(data2{k,1}.TotalPrecip_mm_);
Precip = table2array(Precip);
Precip = str2double(Precip);
A.TotalPrecip_mm_ = (Precip);
A = table2timetable(A);
idx = ~any(ismissing(A),2);
A = A(idx,:);
B = sortrows(A,1,'descend');
B = timetable2table(B);
MaxPoints(k,:) = B(1,:);
end
end