summaryrefslogtreecommitdiff
path: root/modules/elementary_functions/macros/union.sci
blob: f6f344e65effa23d0696a044b2b4063aa7796252 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
// Copyright (C) DIGITEO - 2011 - Allan CORNET
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

function [x,ka,kb] = union(a, b, orient)
    // returns the union of  unique components of  vector a and b
    // author Serge Steer INRIA

    rhs = argn(2);
    if rhs < 2 then
        error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"), "union", 2));
    end

    if rhs < 3 then
        if argn(1)==1 then
            x=unique([a(:);b(:)])
            x=x';
        else
            kab=[1:size(a,"*"), -(1:size(b,"*"))]
            [x,k]=unique([a(:);b(:)])
            x=x'
            kab=kab(k)
            ka=kab(kab>0)
            kb=-kab(kab<0)
        end
    else
        if  orient==1|orient=="r" then
            if argn(1)==1 then
                x=unique([a;b],"r")
            else
                kab=[1:size(a,"r"), -(1:size(b,"r"))]
                [x,k]=unique([a;b],"r")
                kab=kab(k)
                ka=kab(kab>0)
                kb=-kab(kab<0)
            end
        elseif orient==2|orient=="c" then
            if argn(1)==1 then
                x=unique([a b],"c")
            else
                kab=[1:size(a,"c"), -(1:size(b,"c"))]
                [x,k]=unique([a b],"c")
                kab=kab(k)
                ka=kab(kab>0)
                kb=-kab(kab<0)
            end

        else
            error(msprintf(gettext("%s: Wrong value for input argument #%d: %d,''%s'',%d or ''%s'' expected\n"),"unique",3,1,"r",2,"c"));
        end
    end
endfunction