% Logicke operace
% Sestrojme 2 sloupcove vektory za ucelem
% konstrukce pravdivostnich tabulek:
A=logical([0;0;1;1])
A =
     0
     0
     1
     1
B=logical([0;1;0;1])
B =
     0
     1
     0
     1
% Negace (z B bereme jen prve dve slozky):
[B(1:2),~B(1:2)]
ans =
     0     1
     1     0
% Disjunkce
[A,B,A|B]
ans =
     0     0     0
     0     1     1
     1     0     1
     1     1     1
% Bud a nebo
[A,B,xor(A,B)]
ans =
     0     0     0
     0     1     1
     1     0     1
     1     1     0
% Konjunkce
[A,B,A&B]
ans =
     0     0     0
     0     1     0
     1     0     0
     1     1     1
% Implikace
[A,B,~A|B]
ans =
     0     0     1
     0     1     1
     1     0     0
     1     1     1
% Ekvivalence
[A,B,(~A|B)&(A|~B)]
ans =
     0     0     1
     0     1     0
     1     0     0
     1     1     1
% Operace s ciselnymi mnozinami
% (MATLAB pripousti i opakovani prvku)
% Vylouceni duplicit:
unique(A)
ans =
     0
     1
% Hledani prvku jedne mnoziny ve druhe:
help ismember

 ISMEMBER True for set member.
    ISMEMBER(A,S) for the array A returns an array of the same size as A
    containing 1 where the elements of A are in the set S and 0 otherwise.
    A and S can be cell arrays of strings.

    ISMEMBER(A,S,'rows') when A and S are matrices with the same
    number of columns returns a vector containing 1 where the rows of
    A are also rows of S and 0 otherwise.

    [TF,LOC] = ISMEMBER(...) also returns an index array LOC containing the
    highest absolute index in S for each element in A which is a member of S
    and 0 if there is no such index.

    See also UNIQUE, INTERSECT, SETDIFF, SETXOR, UNION.

 Overloaded methods
    help cell/ismember.m
    help opaque/ismember.m

ismember(A,B)
ans =
     1
     1
     1
     1
% 1 na i-te pozici udava, ze i-ty prvek A lezi take v B:
% obdobny priklad s neciselnymi mnozinami:
M1={'prvek1','prvek2','prvek3'}
M1 =
    'prvek1'    'prvek2'    'prvek3'
M2={'prvek2','prvek4','prvek1','prvek5'}
M2 =
    'prvek2'    'prvek4'    'prvek1'    'prvek5'
ismember(M1,M2)
ans =
     1     1     0
% Tedy prvni a druhy prvek z M1 lezi take v M2, treti uz ne
% Chcemeli zjistit, kde se tyto prvky nachazi v M2,
% pouzijeme variantu se dvema vystupy:
[I1,I2]=ismember(M1,M2)
I1 =
     1     1     0
I2 =
     3     1     0
% I1 je totez jako vyse a I2 ma tento vyznam:
% prvek1 je treti v M2, prvek2 je tam prvni a prvek3 tam nelezi
find(I1)
ans =
     1     2
% vyhleda pozice jednicek, tj. poradova cisla prvku v M1 lezicich
% take v M2
% Sjednoceni mnozin:
help union

 UNION  Set union.
    UNION(A,B) when A and B are vectors returns the combined values
    from A and B but with no repetitions.  The result will be sorted.
    A and B can be cell arrays of strings.

    UNION(A,B,'rows') when A are B are matrices with the same number of
    columns returns the combined rows from A and B with no repetitions.

    [C,IA,IB] = UNION(...) also returns index vectors IA and IB such
    that C is a sorted combination of the elements A(IA) and B(IB)
    (or A(IA,:) and B(IB,:)).

    See also UNIQUE, INTERSECT, SETDIFF, SETXOR, ISMEMBER.

 Overloaded methods
    help cell/union.m

union(M1,M2)
ans =
    'prvek1'    'prvek2'    'prvek3'    'prvek4'    'prvek5'
% nebo podrobneji:
[C,IA,IB] = union(M1,M2)
C =
    'prvek1'    'prvek2'    'prvek3'    'prvek4'    'prvek5'
IA =
     3
IB =
     3     1     2     4
% IA rika, ze prvek 3 se do sjednoceni vzal z M1 (treti v poradi) a
% IB rika, ze prvek1,prvek2,prvek4 a prvek5 se vzali z M2
% (jsou tam porade na pozicich 3,1,2,4)
% Podobne funguje prunik
help intersect

 INTERSECT Set intersection.
    INTERSECT(A,B) when A and B are vectors returns the values common
    to both A and B. The result will be sorted.  A and B can be cell
    arrays of strings.

    INTERSECT(A,B,'rows') when A are B are matrices with the same
    number of columns returns the rows common to both A and B.

    [C,IA,IB] = INTERSECT(...) also returns index vectors IA and IB
    such that C = A(IA) and C = B(IB) (or C = A(IA,:) and C = B(IB,:)).

    See also UNIQUE, UNION, SETDIFF, SETXOR, ISMEMBER.

 Overloaded methods
    help cell/intersect.m
    help opaque/intersect.m

% Analogicky rozdil mnozin:
help setdiff

 SETDIFF Set difference.
    SETDIFF(A,B) when A and B are vectors returns the values
    in A that are not in B.  The result will be sorted.  A and B
    can be cell arrays of strings.

    SETDIFF(A,B,'rows') when A are B are matrices with the same
    number of columns returns the rows from A that are not in B.

    [C,I] = SETDIFF(...) also returns an index vector I such that
    C = A(I) (or C = A(I,:)).

    See also UNIQUE, UNION, INTERSECT, SETXOR, ISMEMBER.

 Overloaded methods
    help cell/setdiff.m
    help opaque/setdiff.m

% a symetricka diference:
help setxor

 SETXOR Set exclusive-or.
    SETXOR(A,B) when A and B are vectors returns the values that are
    not in the intersection of A and B.  The result will be sorted.
    A and B can be cell arrays of strings.

    SETXOR(A,B,'rows') when A are B are matrices with the same number
    of columns returns the rows that are not in the intersection
    of A and B.

    [C,IA,IB] = SETXOR(...) also returns index vectors IA and IB such
    that C is a sorted combination of the elements of A(IA) and B(IB)
    (or A(IA,:) and B(IB,:)).

    See also UNIQUE, UNION, INTERSECT, SETDIFF, ISMEMBER.

 Overloaded methods
    help cell/setxor.m
    help opaque/setxor.m

diary off
