N1 = (-5:5:5)';N2 = [1:5;2:2:10;primes(11)];N3 = (1:4)'*(11:14);

% SL5
N1(end:-1:1)
N2(:, 2:2:end)
N3(1:2:end, :)
N2(2, [2 4 5])
A = zeros(3, 4), A(:) = 1:12, A = A',

% SL6:
clear; clc;
x = 1:20;
S = cumsum(x);

L = cumsum(x(2:2:20)),

L(end)

% SL10:
A = rand(6);
B = ones(6);
A([2:3 5], :) = B([1 1 1], :)

A([2:3 5], :) = B(ones(1, 3), 1:6)

B = magic(5);
A([2:3 5], 1:5) = B(ones(1, 3), :)

% SL11:
M(:, :, 1) = eye(3),
M(:, :, 2) = ones(3),
M(:, :, 3) = diag([2 3 5]),

M(1:2, 1:2, 1) = NaN

% SL25:
clear; clc;        % vymažeme Workspace
N  = 5; V = 40;    % perioda, vzorkování
mu = 0; sigma = 1; % normální rozložení
C  = sqrt(2*pi); om0 = pi; % signál
t  = linspace(0, N*1, N*V);
s_t = C*sin(2*om0*t) + ...
(mu + sigma*randn(1, N*V));
plot(t, s_t);

% SL26:
smin = -9/10; smax = pi/2;
sp_t_min = max(s_t, smin);
sp_t     = min(sp_t_min, smax);

close all; 
plot(t, s_t); hold on;
stem(t, sp_t, 'r');

% SL35:
%% skript loanRepayment.m
clear; clc;
r = 0.1:.01:0.2; % interest on a loan is vectorized
A = 1e3;
n = 12;
k = 15;

P = r*A.*(1 + r/n).^(n*k) ./ (n.*((1 + r/n).^(n*k) - 1));

disp(P');         % monthly instalments
disp(P'*n*k - A); % overpayment

% SL38:
%% script loanRepayment.m calculates regular repayment
clear; clc;
r = 0.1:.01:0.2;
A = input('zadejte A = ');
n = input('zadejte n = ');
keyboard; % insert new data (A,n), then type „return“)
k = 15;
P = r*A.*(1 + r/n).^(n*k) ./ (n.*((1 + r/n).^(n*k) - 1));
pause; % program will continue after pressing any key
disp(P'); disp(P'*n*k - A);

% SL43:
X = zeros(1, 45);
X(6:15) = 1;
X(16:25) = 2;
X(25:end) = 2:-2/20:0;
stem(X, 'r');

% or...
X = [zeros(1, 5) ones(1, 10) 2*ones(1, 9) 2:-2/20:0];
stem(X, 'r');
