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: analyze_redetection.m
    path of file: ./repos/toolkit-legacy/analysis
    
    the code of the file until where you have to start completion: function [result] = analyze_redetection(experiment, trackers, sequences, varargin)
% analyze_redetection Performs redetection analysis
%
% Looks for the first failure and records how long it takes tracker to
% recover after it.
%

    
function [result] = analyze_redetection(experiment, trackers, sequences, varargin)
% analyze_redetection Performs redetection analysis
%
% Looks for the first failure and records how long it takes tracker to
% recover after it.
%
% Input:
% - experiment (structure): A valid experiment structures.
% - trackers (cell): A cell array of valid tracker descriptor structures.
% - sequences (cell): A cell array of valid sequence descriptor structures.
%
% Output:
% - result (structure):
%   - length (matrix): number of frames to redetecton (NaN if not
%   redetected)
%   - success (matrix): number of tries where redetection occured

    for i = 1:2:length(varargin)
        switch lower(varargin{i})
            otherwise
                error(['Unknown switch ', varargin{i},'!']) ;
        end