-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW4_CW.m
97 lines (81 loc) · 2.16 KB
/
HW4_CW.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
%HW 4
%Use textscan to open file and remove
fid = fopen('hw4_data.txt');
units = fgetl(fid);
fgetl(fid);
[data] = textscan(fid, '%d%d%d%d%d%d%f%f%f%f%f%d%f%f%f%f%f%f');
fclose(fid);
%Save time variables
yr = double(data{1});
mo = double(data{2});
dy = double(data{3});
hr = double(data{4});
mn = double(data{5});
ss = zeros(length(data{1}),1);
airtemp = data{14};
%Checking sizes
size(ss);
size(yr);
%Using datetime to convert times
t = datetime(yr,mo,dy);
t2 = datetime(yr,mo,dy,hr,mn,ss, 'Format','dd-MMM-uuuu');
%Figure of airtemp
figure1 = plot(t2,airtemp);
ylabel('Air Temperature (C)')
xlabel('Time')
figure1
%%
%Scatter plot
waveheight = data{9};
windspeed = data{7};
figure2 = scatter(windspeed, waveheight)
figure2
%Not correlated...
%% Part 2
%Write in a file
%Average daily values...
%write in a file that doesnt have hh or mn
% for j = unique(mo)
% for i = unique(dy)
% find(dy == i)
% %wave_avg = mean(waveheight(temp))
% end
% end
%
% t4 = datenum(t);
% t4;
%
% for j = 1:length(unique(t4))
% idx_day = find(t4 == t4(j));
% avg = mean(waveheight(idx_day));
% avg
% end
%%%%%%%%%%%%%%% epic fail :(
%%
%Saving variables
WDIR = data{6};
WSPD = data{7};
GST = data{8};
WVHT = data{9};
DPD = data{10};
APD = data{11};
MWD = data{12};
PRES = data{13};
ATMP = data{14};
WTMP = data{15};
DEWP = data{16};
VIS = data{17};
TIDE = data{18};
%setting up timetable for new data
Time = t;
average = table(Time, WDIR, WSPD, GST, WVHT, DPD, APD, MWD, PRES, ATMP, WTMP, DEWP, VIS, TIDE);
TimeTable = table2timetable(average);
%Setting daily averages usint retime function
DailyAvg = retime(TimeTable, 'daily', 'mean');
DailyAvg = timetable2table(DailyAvg);
%Setting up reasnable decibals for variables
DailyAvg{:,["WDIR", "MWD"]} = round(DailyAvg{:,["WDIR", "MWD"]});
DailyAvg{:,["WSPD", "GST", "PRES", "ATMP", "WTMP"]} = round(DailyAvg{:,["WSPD", "GST", "PRES", "ATMP", "WTMP"]},1);
DailyAvg{:,["WVHT", "DPD", "APD", "TIDE"]} = round(DailyAvg{:,["WVHT", "DPD", "APD", "TIDE"]},2);
%Table output :)
writetable(DailyAvg, 'hw4_daily_data.txt', 'Delimiter','\t')