Using the min and max function for form a new variable
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello
I am calculating HDD (heating degree days) and CDD (cooling degree days)and have managed to reshape the data to get a dailyT =reshape(data:,4)24,365). Now I need to use the min and max functions to create new variables (1 x 365) of daily min and max temperature and I am stuck on this stage.
Please can you assist on how to do this.
Regards
Farai
0 Kommentare
Antworten (3)
Adam
am 27 Okt. 2014
Bearbeitet: Adam
am 27 Okt. 2014
If your data is (24,365) then you can just use the normal form:
dailyMins = min( data );
dailyMaxes = max( data );
to get (1,365)-sized results.
If you wanted to be explicit you can use:
dailyMins = min( data, [], 1 );
to tell min to calculate along dimension 1, thus returning a result of size equal to dimension 2, but since this is the default behaviour that is un-necessary. However, if your data happened to be (365,24) then you could use this method with a '2' as the final argument to achieve the same result.
0 Kommentare
Farai Mwashita
am 28 Okt. 2014
2 Kommentare
Adam
am 28 Okt. 2014
That is more than a reshape option, you would need to break down your 365 days into months, average each of these and then end up with a length 12 result.
e.g.
m = [31 28 31 30 31 30 31 31 30 31 30 31];
to give you the lengths of each month. Then a generic version of the following example:
monthlyAverage(1) = mean( dailyMins( 1:m(1) ) )
monthlyAverage(2) = mean( dailyMins( (m(1) + 1):( m(1) + m(2) ) ) );
etc, etc.
There are neater ways to do that of course in a generalised way than just writing out 12 hard-coded lines, but I'll leave that as an exercise for you.
You may find
cumsum( m );
to be very useful in simplifying the indexing into m.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!