function totalDistance = distanceTravelled(x,y,z)
% DISTANCETRAVELLED
% Use as: totalDistance = distanceTravelled(x,y,z)
% Given a set of 3 numerical vectors: x, y, and z (of same length),
% this calculates the distance between all the points, using the
% distance formula. The result is an approximation, since the totalDistance
% value is rounded up in the end.
%
% by Caroline. Fall 2014.
% TESTED and works for Exam3's data, assuming part1 of the requirements was
% followed and is correct.
%get rid of nan's
vecX1 = x(~isnan(x));
vecY1 = y(~isnan(y));
vecZ1 = z(~isnan(z));
%make a copy of elements, but shifted so we can apply distance formula 2by2
vecX2 = vecX1(2:end);
vecY2 = vecY1(2:end);
vecZ2 = vecZ1(2:end);
%get rid of last element of original vectors, same dimension for formula
vecX1(end)=[];
vecY1(end)=[];
vecZ1(end)=[];
%apply distance formula
totalDistance = ceil(sum(sqrt((vecX2-vecX1).^2+(vecY2-vecY1).^2+(vecZ2-vecZ1).^2)));