You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: getTrials_thetamaze.m
    path of file: ./repos/CellExplorer/calc_CellMetrics
    
    the code of the file until where you have to start completion: function circular_track = getTrials_thetamaze(circular_track, maze, plots)
% Determines trials for position data along a circular_track (2-dimensional path)
%
% circular_track :
%    Required fields in struct:
%    .timestamps : timestamps in seconds
%    .position.x : x position
%    .position.y : y position

    
function circular_track = getTrials_thetamaze(circular_track, maze, plots)
% Determines trials for position data along a circular_track (2-dimensional path)
%
% circular_track :
%    Required fields in struct:
%    .timestamps : timestamps in seconds
%    .position.x : x position
%    .position.y : y position
%
% maze : maza parameters
%
% plots : show summary plot? 
%
% circular_track - Added fields:
%    .trials.alternation.start
%    .trials.alternation.stop
%    .trials.alternation.trials
%    .trials.alternation.nTrials
%    .trials.alternation.stateName
%
%    .states.left_right
%    .states.error 
%    .stateNames.left_right
%    .stateNames.error

if nargin < 3
    plots = 1;
end