how can I average monthly Windspeed (Ws) data from 1945-2010. The data loaded into a struct, with 2 fields (data.t and data.ws)

1 view (last 30 days)
This is the data struct
filename: 'g4.areaAvgTimeSeries.GLDAS_NOAH025_M_2_0_Wind_f_inst.19480201-20181231.6W_49N_3W_50N.csv'
t: [1×755 double]
Ws: [1×755 double]
function data=load_giovanni_data2(filename)
%fuction to load wind speed data from giovanni
%input is filename of data file
%output is the date/time and speed from the data file
data.filename = filename;
fid = fopen(filename);
for I= 1:10
templ=fgetl(fid);
end
j=1;
while ischar(templ)
temp=textscan(templ,'%s %f', 'Delimiter',',');
data.t(j)=datenum(cell2mat (temp{1}) );
data.Ws(j) = temp{2};
templ=fgetl(fid);
j=j+1;
end
fclose(fid);

Accepted Answer

Akira Agata
Akira Agata on 9 Jan 2019
Thank you for sharing your original CSV file.
By using readtable and retime functions, you can do this task more easily! Following is an simple example.
fileName = 'g4.areaAvgTimeSeries.GLDAS_NOAH025_M_2_0_Wind_f_inst.19480201-20181231.6W_49N_3W_50N.csv';
% Read from CSV file
T = readtable(fileName,'HeaderLines',8);
T.Properties.VariableNames = {'Time','WindSpeed'};
% Convert to timetable and apply retime()
TT = table2timetable(T);
TT = retime(TT,'yearly','mean');
The result is:
>> TT
TT =
63×1 timetable
Time WindSpeed
___________________ _________
1948-01-01 00:00:00 6.8213
1949-01-01 00:00:00 6.2222
1950-01-01 00:00:00 7.0241
1951-01-01 00:00:00 6.7801
...

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!