source: trunk/SRC/Matrix/different.pro @ 230

Last change on this file since 230 was 230, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.6 KB
RevLine 
[2]1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
[230]6; @file_comments
[163]7; calculate the different elements of 2 matrix of positive whole numbers.
[2]8;
[157]9; @categories
10; Calculation
[2]11;
[230]12; @param a {in}{required}
13; arrays of positive integers, which need
[2]14;               not be sorted. Duplicate elements are ignored, as they have no
15;               effect on the result
16;
[230]17; @param b {in}{required}
18; see a
[2]19;
[230]20; @returns
21; tableau
[2]22;
[230]23; @restrictions
24; The empty set is denoted by an array with the first element equal to
[2]25; -1.
26;
[230]27; @restrictions
28; These functions will not be efficient on sparse sets with wide
[2]29; ranges, as they trade memory for efficiency. The HISTOGRAM function
30; is used, which creates arrays of size equal to the range of the
31; resulting set.
32;
[133]33; @examples
[2]34;
[230]35;  IDL> a = [2,4,6,8]
36;  IDL> b = [6,1,3,2]
37;  IDL> different(a,b) = [ 4, 8]         ; Elements in A but not in B
[2]38;
[230]39; @history
40;  http://www.dfanning.com/tips/set_operations.html
[2]41;
[230]42; @version
43; $Id$
[133]44;
[2]45;-
46;------------------------------------------------------------
47;------------------------------------------------------------
48;------------------------------------------------------------
[230]49FUNCTION different, a, b
[114]50;
51  compile_opt idl2, strictarrsubs
52;
[2]53
54   ; = a and (not b) = elements in A but not in B
55
56mina = Min(a, Max=maxa)
57minb = Min(b, Max=maxb)
58IF (minb GT maxa) OR (maxb LT mina) THEN RETURN, a ;No intersection...
59r = Where(Histogram(a, Min=mina, Max=maxa) $
60          *(1-Histogram(b, Min=mina, Max=maxa)), count)
61IF count eq 0 THEN RETURN, -1 ELSE RETURN, r + mina
62END
Note: See TracBrowser for help on using the repository browser.