Daily mean through long time
22 views (last 30 days)
Show older comments
Nada
on 21 Dec 2024 at 12:44
Commented: Star Strider
ungefär 17 timmar ago
Hi All
The variable, the year, the month, the day, the hour, and the minutes are all in a data file.
i need to find a loop that can find out the variable's daily average.
Pay attention to the point that the variable has 24 values during the day. This means that it changes every hour.
Please help me create a loop so that I can find the average daily value for the month and year.
0 Comments
Accepted Answer
Star Strider
on 21 Dec 2024 at 13:42
T1 = readtable('data.xls') % Import Data
DateTime = datetime([T1{:,1:5} zeros(size(T1,1),1)]); % Create ‘datetime’ Array From Available Data & Add ‘zeros’ Vector Of Seconds
T1 = removevars(T1, 1:5); % Remove Original Datee & Time Data
T1 = addvars(T1, DateTime, Before=1) % Add New ‘datetime’ Array
TT1 = table2timetable(T1); % Converet To ‘timetable’
TT1 = retime(TT1, 'daily', 'mean') % Calculate & Show Results
[t1,t2] = bounds(T1.DateTime(T1.avs >= 5))
figure
plot(T1.DateTime, T1.avs, DisplayName='Original Data')
hold on
stairs(TT1.DateTime, TT1.avs, DisplayName='Daily Mean', LineWidth=2)
hold off
grid
xlim([t1 t2]+[-1 1]*days(3))
xlabel('Time')
ylabel('avs')
legend(Location='SW')
.
2 Comments
More Answers (1)
See Also
Categories
Find more on Dates and Time 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!