Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
find group of numbers are within a specified interval

Subject: find group of numbers are within a specified interval

From: Mike

Date: 11 Sep, 2013 07:55:28

Message: 1 of 1

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?

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us