No BSD License  

Highlights from
INRANGE

3.0

3.0 | 1 rating Rate this file 2 Downloads (last 30 days) File Size: 3.39 KB File ID: #12591

INRANGE

by David Fass

 

10 Oct 2006 (Updated 23 Oct 2006)

INRANGE tests if values are within a specified range (interval).

| Watch this File

File Information
Description

INRANGE tests if values are within a specified range (interval).

INRANGE(X,RANGE) tests if the values in X are within the range specified by RANGE. X can be a vector or matrix.

RANGE is a range in the form [LOW HIGH] against which each value in X will be tested. RANGE can also be a two-column vector whose ith row is of form RANGE(i,:) = [LOW HIGH]. In this form, input X must be a vector with the same length as RANGE, and each element of X is tested against the range in the corresponding row of RANGE.

INRANGE(X,RANGE,BOUNDARY) specifies whether the endpoints of the specified range should be included or excluded from the interval. The options for BOUNDARY are:

       'includeboth' : Both end points included in interval (default)
       'includeleft' : Left end point only included in interval
       'includeright': Right end point only included in interval
       'excludeboth' : Neither end point included in interval

If the LOW and HIGH values for RANGE are equal, that single value will be found in range only under the 'includeboth' option (default). Otherwise, for this case, no values will be found in range.

   Examples:
      X = 1:10
      X =
          1 2 3 4 5 6 7 8 9 10

      Y = inrange(X,[5 7.2],'includeboth')
      Y =
          0 0 0 0 1 1 1 0 0 0

      Y = inrange(X,[5 7.2],'excludeboth')
      Y =
          0 0 0 0 0 1 1 0 0 0

   See also ISVALID.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
10 Oct 2006 Jos x

This submission can be improved:
1) no need for find, use logical indexing;
2) return a logical array (false/true) instead of a zero/one array;
3)for a 1x2 input R you do no need the repmat, as you split it into two scalars;
4)reduce overhead: first get the size of X, than use X = X(:), and finally reshape Y using the stored size of X;
5) why not make a default value for boundary
6) it may return some unexpected results when LOW==HIGH;
7) Take a look at submission #9428 by John D'Errico how to implement "boundary" effectively.

Please login to add a comment or rating.
Updates
23 Oct 2006

Made most of the fixes suggested by "Jos x" (thanks!). See M-file help.

Tag Activity for this File
Tag Applied By Date/Time
in range David Fass 22 Oct 2008 08:43:14
in interval David Fass 22 Oct 2008 08:43:14
test interval David Fass 22 Oct 2008 08:43:14
test range David Fass 22 Oct 2008 08:43:14
range David Fass 22 Oct 2008 08:43:15

Contact us at files@mathworks.com