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.

 Risposta accettata

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.

Più risposte (1)

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 Commenti

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.
That's great! Thanks!!
Again, my pleasure!

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by