You're testing that n<=length(u), but then you immediately increment it. You'd need to adjust your test limit.
Better yet, avoid while loops if you already know the number of iterations you need. It's more concise, and there are fewer things to go wrong.
if (length(u) == length(v) && iscolumn(u) && iscolumn(v))
c = zeros(length(u), 1);
c(n) = (u(n)-v(n))^2;
distvect = sqrt(sum(c));
theta = acos((dot(u,v))/(norm(u)*norm(v)));
distvect = -1;
theta = -1;