% Priklad 1
A=-5+round(10*rand(3,5))
A =
     0     1    -2     0     3
     4     3    -2     2     1
     3     2    -2    -2    -1
B=-5+round(10*rand(3,5))
B =
     2     2     5    -3    -2
     0     1     0     5     4
    -1     3     4    -2     2
A=-5+round(10*rand(3,4))
A =
    -4    -3    -2     5
    -5    -2     0     1
     4     2    -4    -1
B=-5+round(10*rand(3,4))
B =
     0    -3     0    -1
    -2     1     1     3
    -1     3    -3     2
% Priklad 2
T1 = A.*B>0
T1 =
     0     1     0     0
     1     0     0     1
     0     1     1     0
T2 = A.*B<0
T2 =
     0     0     0     1
     0     1     0     0
     1     0     0     1
T3 = A.*B==0
T3 =
     1     0     1     0
     0     0     1     0
     0     0     0     0
T1*'+'
ans =
     0    43     0     0
    43     0     0    43
     0    43    43     0
char(T1*'+')
ans =
 +  
+  +
 ++ 
double(char(T1*'+'))
ans =
     0    43     0     0
    43     0     0    43
     0    43    43     0
char(T1*'+'+T2*'-'+T3*'.')
ans =
.+.-
+-.+
-++-
T=char(T1*'+'+T2*'-'+T3*'.')
T =
.+.-
+-.+
-++-
T=char((A.*B>0)*'+'+(A.*B<0)*'-'+(A.*B==0)*'.')
T =
.+.-
+-.+
-++-
% Priklad 3
A<0
ans =
     1     1     1     0
     1     1     0     0
     0     0     1     1
A>0
ans =
     0     0     0     1
     0     0     0     1
     1     1     0     0
A(A<0)
ans =
    -4
    -5
    -3
    -2
    -2
    -4
    -1
A(A>0)
ans =
     4
     2
     5
     1
-sum(A(A<0))
ans =
    21
-sum(A(A<0))<sum(A(A>0))
ans =
     0
% Relace neplati
% Priklad 4
A(:)
ans =
    -4
    -5
     4
    -3
    -2
     2
    -2
     0
    -4
     5
     1
    -1
B(:)
ans =
     0
    -2
    -1
    -3
     1
     3
     0
     1
    -3
    -1
     3
     2
[A(:);B(:)]
ans =
    -4
    -5
     4
    -3
    -2
     2
    -2
     0
    -4
     5
     1
    -1
     0
    -2
    -1
    -3
     1
     3
     0
     1
    -3
    -1
     3
     2
[A(:);B(:)]==0
ans =
     0
     0
     0
     0
     0
     0
     0
     1
     0
     0
     0
     0
     1
     0
     0
     0
     0
     0
     1
     0
     0
     0
     0
     0
sum([A(:);B(:)]==0)
ans =
     3
A
A =
    -4    -3    -2     5
    -5    -2     0     1
     4     2    -4    -1
B
B =
     0    -3     0    -1
    -2     1     1     3
    -1     3    -3     2
% Priklad 5
[m,n]=size(A)
m =
     3
n =
     4
C=(1:m).'*ones(1,n)-ones(m,1)*(1:n)
C =
     0    -1    -2    -3
     1     0    -1    -2
     2     1     0    -1
D=zeros(m,n)
D =
     0     0     0     0
     0     0     0     0
     0     0     0     0
D(C==0)=A(C==0)
D =
    -4     0     0     0
     0    -2     0     0
     0     0    -4     0
A
A =
    -4    -3    -2     5
    -5    -2     0     1
     4     2    -4    -1
L=zeros(m,n)
L =
     0     0     0     0
     0     0     0     0
     0     0     0     0
L(C>0)=A(C>0)
L =
     0     0     0     0
    -5     0     0     0
     4     2     0     0
U=zeros(m,n)
U =
     0     0     0     0
     0     0     0     0
     0     0     0     0
U(C<0)=A(C<0)
U =
     0    -3    -2     5
     0     0     0     1
     0     0     0    -1
% Kontrola
L+D+U
ans =
    -4    -3    -2     5
    -5    -2     0     1
     4     2    -4    -1
A
A =
    -4    -3    -2     5
    -5    -2     0     1
     4     2    -4    -1
diary off
