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

Last change on this file since 378 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
RevLine 
[2]1;+
2;
[230]3; @file_comments
[373]4; find the different elements of 2 matrixes of positive whole numbers.
[2]5;
[373]6; see also <pro>union</pro> and <pro>inter</pro>.
7;
[157]8; @categories
9; Calculation
[2]10;
[232]11; @param a {in}{required}
[230]12; arrays of positive integers, which need
[372]13; not be sorted. Duplicate elements are ignored, as they have no
14; effect on the result
[2]15;
[232]16; @param b {in}{required}
[230]17; see a
[2]18;
[230]19; @returns
[373]20; an array containing the set of values in only a.
[2]21;
[230]22; The empty set is denoted by an array with the first element equal to
[2]23; -1.
24;
[232]25; @restrictions
[230]26; These functions will not be efficient on sparse sets with wide
[2]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;
[133]31; @examples
[2]32;
[371]33;   IDL> a = [2,4,6,8]
34;   IDL> b = [6,1,3,2]
[2]35;
[373]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;
[230]46; @history
[232]47; <a href="http://www.dfanning.com/tips/set_operations.html"/>
[2]48;
[230]49; @version
50; $Id$
[133]51;
[2]52;-
[230]53FUNCTION different, a, b
[114]54;
55  compile_opt idl2, strictarrsubs
56;
[2]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.