Using the min and max function for form a new variable

4 ビュー (過去 30 日間)
Farai Mwashita
Farai Mwashita 2014 年 10 月 27 日
コメント済み: Farai Mwashita 2014 年 10 月 28 日
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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by