time series, find number of times a value is reached

3 次查看(过去 30 天)
Hello,
I have a multi-year temperature time-series. I want to know how many times temperature drops a given amount (say, 5C) over a given time limit (say, within 6 hrs) within each year. Then, I would like to make a box plot to compare across each year. I have a temp variable, yr variable, month variable, day variable and hr variable. For example, there may have been 300 6C drops in 2014, 200 6C drops in 2013, etc. Your help is appreciated!
***I have made some progress on this, although it is only over the time limit of 1 day rather than 6 hrs
[DMY ID]=findgroups(day,month,yr); %find groups of day month and year
maxt=splitapply(@max,temp,DMY); %find max of each DMY
mint=splitapply(@min,temp,DMY); %find min of each DMY
difft=maxt-mint; %calculate the difference
[c ia c]=unique(DMY);
table=[difft day(ia) m(ia) yr(ia)]; %create table with new data
I think the next step is to find how many times the difft is >=5 within each yr
[D ID]=findgroups(yr(ia));
myfunc=@(x)[find(x>5)];
xxx=splitapply(myfunc,difft,D); % this gives me error:
% The function '@(x)[find(x>5)]' returned a non-scalar value when applied to the 1st group
% of data.
%
% To compute nonscalar values for each group, create an anonymous function to return each
% value in a scalar cell:
%
% @(x){[find(x>5)]}

回答(1 个)

Image Analyst
Image Analyst 2020-12-19
You forgot to attach any data. So here is untested code:
[~, numDrops] = bwlabel(diff(y) <= -6);
where y is your temperature measurement in 6 hour increments.
  2 个评论
akk
akk 2020-12-19
编辑:akk 2020-12-19
Sample dataset is now attached. Can the code also define per year? Also, i do not have the image processing toolbox, and my data are not divided in 6hr increments. The data are collected at higher resolution.
Image Analyst
Image Analyst 2020-12-19
If you don't have bwlabel(), you can use (the less convenient) findgroups(). You can do
y = randi(100, 1, 20) % Create sample data.
differences = [0, diff(y)]
d = double(differences <= -6)
numGroups = length(strfind(d, [0 1]))
where y is your data at every 6 hour period. I'm sure you can figure out how to manipulate your time data into an array sampled every 6 hours. You don't need us to do that part for you, do you?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by