Using the min and max function for form a new variable

5 次查看(过去 30 天)
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

回答(3 个)

Adam
Adam 2014-10-27
编辑:Adam 2014-10-27
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.

Farai Mwashita
Farai Mwashita 2014-10-28
Hello Adam
Thank you for your help.

Farai Mwashita
Farai Mwashita 2014-10-28
hello
I have managed to calculate the average daily temperatures (1 x 365) and now I need to reshape this into monthly averages. I have been told the loop function can used, can you please assist on how to do so?
Regards
Farai
  2 个评论
Adam
Adam 2014-10-28
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.
Farai Mwashita
Farai Mwashita 2014-10-28
Hello
When i try to calculate for the second month, I get an error message saying unbalanced or enexpected parentesis or bracket. I can't seem to get past this stage.
Regards
Farai

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by