function [x1s, x2s] = indices(origin, fs, poc, duration)
% indices exactly determines a sinusoid trial areas in the input and output
% eeg signal
%
%% Syntax
%
% [x1, x2] = indices(origin, fs, poc, duration)
%
%% Description
%
% The function serves to exactly determination of the sinusoid trials
% indices. From the initial conditions, the beginning indices of sinusoid
% trials, the ending sinusoid indices are estimated using a sinusoid trial
% duration. The results are the exactly bordered sinusoid trials.
%
%% Input
%
% origin: a matrix with eeg signal, a number of rows corresponds to a
%         number of channels, the output from function loading.m
%
% fs: a sampling frequency, the output of function loading.m
%
% poc: a n-by-1 vector containing a beginning indices of sinusoid trials, the output of function loading.m
%
% duration: a n-by-1 vector containing a time duration of each sinusoid
%           trial, the output of function loading.m
%
%% Output
%
% x1: a 1-by-n structure that in the row contains a cell arrays of the sinusoid trials
%     for the input signal, in the column contains particular cell arrays
%     of the sinusoid trials
%
% x2: a z-by-n structure that in rows contains a cell arrays of the sinusoid trials 
%     for the output signals, in columns there are particular cell arays of
%     the sinusoid trials
%
%% Author: Veronika Svozilová
%% Date: 07/04/2015
%
rozmer = size(origin);
for n = 1:length(poc)
    for z = 3:rozmer(1,1)
      kon(n) = poc(n) + duration(n)*fs;
      x1s{1,n} = origin(1,poc(n):kon(n));
      x22{z,n} = origin(z,poc(n):kon(n));  
    end
end
 
x2s = x22( [3:end] , : );

end

