x = [ 1.2   1.4   4.3   7.9   9.1   6.4   3.2   1.8];
y = [ 9.9  11.3  33.9  75.4  87.9  56.0  22.3  11.2];

figure(1);
plot(x,y, 'o');   % zobraz data jako jednotlive body
%{
fprintf('\nJdi na Figure1 --> Tools --> Basic Fitting\n');
fprintf('Pro pokracovani stiskni ENTER');
pause;
fprintf('\n');
%}

% priprav data pro aproximaci krivkou
[X, Y] = prepareCurveData(x, y);

% nastav typ aproximace a volitelne parametry
ft = fittype('poly1');
op = fitoptions(ft);
op.Lower = [-Inf -Inf];
op.Upper = [Inf Inf];

% aproximace zvolenym typem krivky
[aprox, gof] = fit(X, Y, ft, op);

figure(2), set(2, 'Name', 'Linearni aproximace' );
h = plot(aprox, X, Y, 'o');
legend( h, 'Namerene hodnoty', 'Linearni aproximace', ...
           'Location', 'SouthEast');
xlabel( 'X' );
ylabel( 'Y' );
grid on
