Home > FMAToolbox > General > CountInIntervals.m

CountInIntervals

PURPOSE ^

CountInIntervals - Count samples that fall in each of a list of intervals.

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CountInIntervals - Count samples that fall in each of a list of intervals.

  The equivalent Matlab code is trivial

      for i = 1:length(intervals),
        j = find(values>=intervals(i,1)&values<=intervals(i,2));
        counts(i) = length(j);
      end

  but becomes extremely slow when dealing with very large lists.
  This function can dramatically speed up things whenever one needs
  to count values in a long list of intervals.

  USAGE

    counts = CountInIntervals(values,intervals)

    values          values to test
    intervals       [start,stop] pairs in ascending order

  OUTPUT

    counts         number of values that fall in each interval

  SEE

    See also ConsolidateIntervals, SubtractIntervals, ExcludeIntervals,
    InIntervals, Restrict, FindInInterval, PlotIntervals.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %CountInIntervals - Count samples that fall in each of a list of intervals.
0002 %
0003 %  The equivalent Matlab code is trivial
0004 %
0005 %      for i = 1:length(intervals),
0006 %        j = find(values>=intervals(i,1)&values<=intervals(i,2));
0007 %        counts(i) = length(j);
0008 %      end
0009 %
0010 %  but becomes extremely slow when dealing with very large lists.
0011 %  This function can dramatically speed up things whenever one needs
0012 %  to count values in a long list of intervals.
0013 %
0014 %  USAGE
0015 %
0016 %    counts = CountInIntervals(values,intervals)
0017 %
0018 %    values          values to test
0019 %    intervals       [start,stop] pairs in ascending order
0020 %
0021 %  OUTPUT
0022 %
0023 %    counts         number of values that fall in each interval
0024 %
0025 %  SEE
0026 %
0027 %    See also ConsolidateIntervals, SubtractIntervals, ExcludeIntervals,
0028 %    InIntervals, Restrict, FindInInterval, PlotIntervals.
0029 
0030 % Copyright (C) 2009-2011 by Michaƫl Zugaro
0031 %
0032 % This program is free software; you can redistribute it and/or modify
0033 % it under the terms of the GNU General Public License as published by
0034 % the Free Software Foundation; either version 3 of the License, or
0035 % (at your option) any later version.

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005