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

Last change on this file since 373 was 373, checked in by pinsard, 16 years ago

improvements of headers (examples and results)

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