How to get max/min temp data from hourly data?

Hi,
I have a dataset of hourly data for a 30+day period and have no clue where to start to get the daily min and max temperatures for each day of this period? Can anyone help me? Imagine that column1 is the day of year, column 2 is the time, and column 3 is the hourly temp.

 채택된 답변

Star Strider
Star Strider 2015년 1월 29일

0 개 추천

Here is one approach:
D0 = datenum([2014 01 01 0 0 0]); % Start Date
Dv = D0 + [1/24:1/24:30]'; % Create Date Number Vector
Ds = datestr(Dv, 'dd.mm.yyyy HH'); % Convert To Date Strings
T = 10*sin([1/24:1/24:30]*2*pi*24)+15 + 2*randn(size(Dv')); % Temperature
Data30d = {Ds T'}; % Original Data
Tv30 = Data30d{2}; % Get Temperature Vector
Tv24 = reshape(Tv30, 24, []); % Reshape To 30 Days
Tmax = max(Tv24); % Get Daily Max
Tmin = min(Tv24); % Get Daily Min
I had to create the data, but this should work.
NOTE that the reshape function needs data for full 24-hour days for it (and my code) to work correctly.

추가 답변 (1개)

JAG2024
JAG2024 2015년 1월 29일

0 개 추천

Thanks so much! Yup, I was able to modify it and get it to work. I ended up with something like this for multiple sites:
load IButtonsTemp14.txt
SQ4 = IButtonsTemp14(:,5);
TempSQ = SQ4(6:653); %Rows of data that I want
SQ27 = TempSQ; %For 27 day period
SQ24 = reshape(SQ27, 24, []); %Shape into 24-hr segments
SQmax = max(SQ24);
SQmin = min(SQ24);
I would also like to be able to use a for loop to do the same thing. But I can't seem to get it to work. If you have any thoughts about whether this is possible, I would love to hear it.

댓글 수: 3

My pleasure!
The problem with for loops is that they’re inefficient, and aren’t the best option for large problems. The built-in functions are optimised, and in many instances use compiled C-code to do the requisite operations.
One way to generate my ‘Tv24’ matrix with a for loop is:
for k1 = 1:30
ofst = (k1-1)*24 + [1:24];
Tv24(:,k1) = Tv30(ofst);
end
There are likely other variations that would work as well.
Still another option uses the mat2cell function:
Tv24 = mat2cell(Tv30, repmat(24,1,30), 1);
Choose the one that is best for your application.
JAG2024
JAG2024 2015년 1월 30일
That's great! Thanks!!
Again, my pleasure!

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

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

질문:

2015년 1월 29일

댓글:

2015년 1월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by