How to find days that are togheter

2 ビュー (過去 30 日間)
Marie
Marie 2013 年 11 月 5 日
編集済み: Marc Jakobi 2013 年 11 月 30 日
Hi! I need help to find if there are 5 consequtive days with the temperature over 25 degrees in my data.
This is what I have now. I have taken out the days where the temperature has been over 25 degrees. Now I want to see if there has been any heat waves occuring. The definition of a heat wave is that there are five consecutive days with the maximum temperature over 25 degrees
Data=importdata('');
%Define different parameters
year=Data(:,1);
month=Data(:,2);
day=Data(:,3);
time=Data(:,4);
temp=Data(:,5);
%
%Find the number of times each year the temperature is over 25
%degrees
M=[];
S=find(temp>25)
M=[year(S),month(S),day(S),S];
M
%
Example of how M looks like
  • Year Month Day
  • 1991 7 3
  • 1991 7 3
  • 1991 7 4
  • 1991 7 4
  • 1991 7 4
  • 1991 7 5
  • 1991 7 5
  • 1991 7 5
  • 1991 7 5
  • 1991 7 6
  • 1991 7 6
  • 1991 7 6
  • 1991 7 7
  • 1991 7 7
  • 1991 7 7
  • 1991 7 8
  • 1991 7 8
  • 1991 7 8
As there is 24 values for each day (one per hour) one day can show several values.
I would like to find the periods when a heat wave has occured, but also plot how many heatwaves there has been in one year.
Thankful for any help that can leed me on the right way to the answer.
Best regards Marie

回答 (2 件)

Marc Jakobi
Marc Jakobi 2013 年 11 月 5 日
%Get rid of "multiple-days"
[a,~] = size(M);
M2 = M(1,:);
for i = 2:a
if M(i,3) ~= M(i-1,3)
M2 = [M2; M(i,:)];
end
end
%Extract groups of >= 5 consecutive days
[a,~] = size(M2);
Consec = [];
for i = 5:a
if M2(i,3) == M2(i-4,3)
Consec = [Consec; M2(i-5:i,:)];
end
end
Hope this helps. It's getting a little late where I am to think of a way to plot it. You could create a "clone" of M using datenum(), such as Mnum = datenum(M) and creating a vector from
WholeYearNum = (datenum(1991 1 1):1./*number of hours in that year*:datenum(1991 12 30))
Use that vector as a reference so you know where to fill in the gaps with zeros and plot it with the amount of hours in that year.
  3 件のコメント
Marie
Marie 2013 年 11 月 6 日
Hi! Everything works except for that the Consec matrix is empty. Do you have any suggestions on how to solve this?
Marie
Marc Jakobi
Marc Jakobi 2013 年 11 月 30 日
編集済み: Marc Jakobi 2013 年 11 月 30 日
Sorry for getting back to you so late. Somehow I haven't been receiving e-mails from MathWorks when I get a reply lately...
I don't have access to Matlab right now so I can't give you a definite answer. But I checked my code and it looks like I made a stupid mistake. I tried to extract groups larger than five days in the "consec" loop using the vector M2. But M2 is the vector I created to get rid of the multiple days, so of course consec will remain empty. Try using M instead of M2 in the second loop. a will have to be adjusted to size(M) instead of M2 as well.

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


Andrei Bobrov
Andrei Bobrov 2013 年 11 月 6 日
編集済み: Andrei Bobrov 2013 年 11 月 6 日
t0 = temp(:)' >= 25;
tt = [strfind([0,t0],[0 1]);strfind([t0,0],[1 0])];
out = cellfun(@(x)Data(x(1):x(2),:),num2cell(tt(:,diff(tt) >= 119),1),'un',0);

カテゴリ

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

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by