Hello, I have a table contains the calendar day of the year and 24-hour frequency. How to get daily max, min, and average temperature from the table?

조회 수: 2 (최근 30일)
  댓글 수: 1
Star Strider
Star Strider 2023년 7월 11일
A relatively straightforward way is to use table2timetable and then retime. The year-month-day information is a bit ambiguous (at least in the sample provided), so you may need to specify it in an options structure created by the detectImportOptions function.

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2023년 7월 11일
Here's one approach:
% a table similar to yours, with only a few days, and only the relevant columns:
t = table(repelem({'2005-01-01'; '2005-02-01'; '2005-03-01'},96,1),-12.35+0.1*(1:288).','VariableNames',{'DAY','AIR_TEMP_DEG_C'})
t = 288×2 table
DAY AIR_TEMP_DEG_C ______________ ______________ {'2005-01-01'} -12.25 {'2005-01-01'} -12.15 {'2005-01-01'} -12.05 {'2005-01-01'} -11.95 {'2005-01-01'} -11.85 {'2005-01-01'} -11.75 {'2005-01-01'} -11.65 {'2005-01-01'} -11.55 {'2005-01-01'} -11.45 {'2005-01-01'} -11.35 {'2005-01-01'} -11.25 {'2005-01-01'} -11.15 {'2005-01-01'} -11.05 {'2005-01-01'} -10.95 {'2005-01-01'} -10.85 {'2005-01-01'} -10.75
% group the DAYs together:
[g, g_id] = findgroups(t.DAY);
% (g_id contains your days, if you should need it:)
g_id
g_id = 3×1 cell array
{'2005-01-01'} {'2005-02-01'} {'2005-03-01'}
% find the min, max, and mean of AIR_TEMP_DEG_C for each DAY:
[min_all, max_all, mean_all] = splitapply(@get_min_max_mean, t.AIR_TEMP_DEG_C, g)
min_all = 3×1
-12.2500 -2.6500 6.9500
max_all = 3×1
-2.7500 6.8500 16.4500
mean_all = 3×1
-7.5000 2.1000 11.7000
function [min_val, max_val, mean_val] = get_min_max_mean(in)
min_val = min(in);
max_val = max(in);
mean_val = mean(in);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by