function [output,errors] = LoadMotion(paths)
    % Loads csv file from Vicon that includes marker data
    %
    % Written by Grant Elliott, 2011
    
    [output,errors]=ProcessPaths(paths,'mot',@(path)LoadMotionCallback(path));
end

function [output,abort] = LoadMotionCallback(path)
    abort=false;
    proc=importdata(path);
    fields=proc.colheaders;
    fields=genvarname(lower(regexprep(fields,'\.','_')));
    data=proc.data;
    markerstart=find(cellfun(@(x)~isempty(regexpi(x,'_px$')),fields),1);
    markerend=find(cellfun(@(x)~isempty(regexpi(x,'_pz$')),fields),1,'last');
    output.Time=data(:,1)';
    output.FileName=path;
    for j=3:markerstart-1
        output.Kinematics.(fields{j})=data(:,j)';
    end
    for j=markerstart:3:markerend
        fname=fields{j};
        fname=fname(1:end-3);
        output.Markers.(fname)=data(:,j:j+2)';
    end
end