Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: find group of numbers are within a specified interval
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Mike

Posts: 336
Registered: 4/17/07
find group of numbers are within a specified interval
Posted: Sep 11, 2013 3:55 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi

% Given some sorted date/time numbers, I'd like to find group of
% date/time numbers
% are within a specified interval, for example, 5 days.
%
% First, I convert date strings to date numbers.
% Given that these numbers are for example:

% sorted numbers
A=[1 25 26 27 28 40 42 50];
n=length(A);
interval=5;
% maximum group number: n
% for every group
for ig=1:n
% find group members
for i=1:n
start_n=A(i);
its_end_n=start_n+interval-1;
idx=A(i+1:end) < its_end_n
group(ig, ?????
end
end
% answer should be:
% group 1: 25 26 27 28
% group 2: 40 42

Any suggestion?



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.