Writing a loop to calculate a seasonal cycle and then plot the seasonal cycle?

13 ビュー (過去 30 日間)
Victoria Woods
Victoria Woods 2018 年 1 月 9 日
コメント済み: Ronald Ssembajwe 2022 年 11 月 30 日
My current code is this:
{for mdo=1:12
index_month = find(month==mdo);
month_mean = mean(avhrr.sst(index_month));
seasonal_cycle(mdo)=month_mean;
s_cycle_month(index_month) = month_mean;
end
hold on
plot(t, month_mean, 'r')}
When I run this, it produces a blank graph. I think the loop is correctly producing the seasonal cycle, how can I get it to plot the graph?
  1 件のコメント
bushra raza
bushra raza 2019 年 1 月 10 日
編集済み: bushra raza 2019 年 1 月 10 日
Hi Victoria,
are you done with seasonal cycle calculations?
i have 30 years hourly data , and i want to see the seasonal cycle, and trend etc and further analysis. please guide me for its start?
Regards,
BNA

サインインしてコメントする。

回答 (2 件)

Chad Greene
Chad Greene 2019 年 3 月 6 日
Check out the season and climatology functions in the Climate Data Toolbox for Matlab. The functions make it easy to extract seasonal cycles, (and they properly detrend the data before the calculation).
  1 件のコメント
Ronald Ssembajwe
Ronald Ssembajwe 2022 年 11 月 30 日
Hi Chad, I've used this tool box and it works perfectly. However, would you care to include mor functions in the toolbox like the one that compute/extracts the Length of the groing season given moisture/precipitation and PET spatio-temporal datasets?

サインインしてコメントする。


Cedric
Cedric 2018 年 1 月 10 日
編集済み: Cedric 2018 年 1 月 10 日
Where is t defined? In addition, month_mean is your intermediary variable; you want to plot either seasonal_cycle or s_cycle_month, which are your output vectors.
  2 件のコメント
Victoria Woods
Victoria Woods 2018 年 1 月 10 日
t is defined earlier on in my code. I've changed my plot to t against s_cycle_month and it doesn't even open a figure anymore.
Cedric
Cedric 2018 年 1 月 11 日
編集済み: Cedric 2018 年 1 月 11 日
Check every variable. Maybe one is an empty array. Try to compute intermediary terms manually, e.g.
index_month = find(month==1)
If it outputs nothing it means that month, which you suppose is a vector with some elements equal to 1, has in fact no element equal to 1. If the output looks fine, then evaluate:
avhrr.sst(index_month)
If the output is not a vector of floating point elements, then maybe avhrr.sst is not what you think it is.
Check every expression for a given month index at first, so you are sure that the inputs are what you think they are, and that the outputs are valid. Once this works, embed it in the loop and try to debug the loop.
Also, try plotting seasonal_cycle first with e.g.
plot( seasonal_cycle ) ;
If you tried plotting s_cycle_month against t, I guess that it means that t is not 1:12. This is a little more complex to debug, because s_cycle_month is more complex than seasonal_cycle (you build the former by re-injecting the mean at positions that correspond to the current month apparently).

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by