tr_merge.m 1.2 KB
function tr_merge(dev)
% TR_MERGE - Merge trajectories of multiple mat files in a single one,
% supposing that all pieces are parts of the same trajectory.
%
% Syntax:  tr_merge(dev)
% 
% Inputs:
%    dev - name of the device, which appear in the first part of the files
%          to merge.
%
% Example:
%    tr_merge('spot24')
%
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: Trajectory files to merge.
% 
% See also: TR_MAP, GPX2MAT
% 
% Author: Dany Dumont
% UQAR/ISMER
% email: dany_dumont@uqar.ca
% Website: http://www.ismer.ca/dumont-dany
% September 2014
% ______________________________________________________________________


curdir = pwd;
matdir = [curdir,'/mat'];

if ~exist(matdir)
    disp(' ERROR : The /mat directory does not exist. Make')
    disp('         sure mat files exist and that they     ')
    disp('         are placed in a directory named mat.   ')
    return
end

files = dir([matdir,'/',dev,'_*.mat']);
nf = length(files);

A = [];
for n = 1:nf
    load([matdir,'/',files(n).name]);
    A = cat(1,A,data);
end

% Sort rows chronologically
A = sortrows(A,1);
% Remove time replicates
A = unique(A,'rows','first');

data = A;

save([matdir,'/',dev,'_merged'],'data');