function testmfile

% load the file that was written out by C-Motion Visual3D
load c:\temp\3Targets_In.mat;

% loop throught the elements
for file=1:length(SIGNAL1_IN)
    [n1,n2]=size(SIGNAL1_IN{file});
    for frame=1:n1
        % Lets average the targets.
        if ((SIGNAL1_IN{file}(frame,1) == -999999)| ...
            (SIGNAL2_IN{file}(frame,1) == -999999)| ...
            (SIGNAL3_IN{file}(frame,1) == -999999))
            SIGNAL_OUT{file}(frame,1)=-999999.0;  % retain the integrity of the missing points.
            SIGNAL_OUT{file}(frame,2)=-999999.0;  % retain the integrity of the missing points.
            SIGNAL_OUT{file}(frame,3)=-999999.0;  % retain the integrity of the missing points.
            SIGNAL_OUT{file}(frame,4)=-999999.0;  % retain the integrity of the missing points.
            SIGNAL_OUT{file}(frame,5)=-999999.0;  % retain the integrity of the missing points.
        else
            SIGNAL_OUT{file}(frame,1)=(SIGNAL1_IN{file}(frame,1) +SIGNAL2_IN{file}(frame,1) +SIGNAL3_IN{file}(frame,1))/3;
            SIGNAL_OUT{file}(frame,2)=(SIGNAL1_IN{file}(frame,2) +SIGNAL2_IN{file}(frame,2) +SIGNAL3_IN{file}(frame,2))/3;
            SIGNAL_OUT{file}(frame,3)=(SIGNAL1_IN{file}(frame,3) +SIGNAL2_IN{file}(frame,3) +SIGNAL3_IN{file}(frame,3))/3;
            SIGNAL_OUT{file}(frame,4)=(SIGNAL1_IN{file}(frame,4) +SIGNAL2_IN{file}(frame,4) +SIGNAL3_IN{file}(frame,4))/3;
            SIGNAL_OUT{file}(frame,5)=(SIGNAL1_IN{file}(frame,5) +SIGNAL2_IN{file}(frame,5) +SIGNAL3_IN{file}(frame,5))/3;
        end
    end
end

% save the file that to be read in by C-Motion Visual3D
% save the variables File_Name and Signal_OUT to the output file
% note that the variables have to be defined explicitly
save c:\temp\averaged_targets_out.mat FILE_NAME SIGNAL_OUT;