function makeCompilation( videoColumn1, videoColumn2, videoColumn3, videoColumn4, videoPath, vidWidth, vidHeight, shape)
%MAKECOMPILATION ( A1, A2, A3, A4, videoPath, Width, Height, Shape) - 
%funkce vytvori a ulozi ve formatu AVI kompilaci ctyr videi.
%   A1, A2, A3, A4  - matice pozorovani (stejne velikosti);
%   Width           - sirka videozaberu;
%   Height          - vyska videozaberu;
%   videoPath       - cilova (existujici) lokace souboru videa.
%   Shape           - tvar vysledne kompilace (1 pro 2x2, 2 pro 1x4).

switch shape
    case 1  % 2x2
        compHeight = vidHeight * 2;
        compWidth  = vidWidth  * 2;
    case 2  % 1x4
        compHeight = vidHeight;
        compWidth  = vidWidth  * 4;
end

compFrame = zeros( compHeight, compWidth, 'uint8' );

frameCount = size( videoColumn1, 2 );

vidWriter = VideoWriter( videoPath );
open( vidWriter );

for t = 1 : frameCount
    % transformace jednotlivych snimku videi ve tvaru sloupcu do obrazku
    vidFrame1 = uint8( reshape( videoColumn1(:,t), vidHeight, vidWidth ) );
    vidFrame2 = uint8( reshape( videoColumn2(:,t), vidHeight, vidWidth ) );
    vidFrame3 = uint8( reshape( videoColumn3(:,t), vidHeight, vidWidth ) );
    vidFrame4 = uint8( reshape( videoColumn4(:,t), vidHeight, vidWidth ) );
    
    % skladani nekolika obrazku do kompilace
    switch shape
        case 1  % 2x2
            compFrame(1:vidHeight, 1:vidWidth) = vidFrame1;
            compFrame(1:vidHeight, (vidWidth+1):(2*vidWidth)) = vidFrame2;
            compFrame((vidHeight+1):(2*vidHeight), 1:vidWidth) = vidFrame3;
            compFrame((vidHeight+1):(2*vidHeight), (vidWidth+1):(2*vidWidth)) = vidFrame4;
        case 2  % 1x4
            compFrame(1:vidHeight, 1:vidWidth) = vidFrame1;
            compFrame(1:vidHeight, (vidWidth+1):(2*vidWidth)) = vidFrame2;
            compFrame(1:vidHeight, (2*vidWidth+1):(3*vidWidth)) = vidFrame3;
            compFrame(1:vidHeight, (3*vidWidth+1):(4*vidWidth)) = vidFrame4;
    end
    
    writeVideo( vidWriter,compFrame );
end

close( vidWriter );
end