1) Return vel as an output of your function. E.g.,
function [vel,vend] = velocity1(dt, ti,tf,vi)
2) Have your driver code and function code in separate files. E.g.,
% A file called velocity1_driver.m (or some other name of your choosing)
dt = 0.5;
ti = 0;
tf = 12;
vi = 0;
[vel,vend] = velocity1(dt, ti, tf, vi);
:
etc
And then a function file
% A file called velocity1.m
function [vel, vend] = velocity1(dt,ti,tf,vi)
:
etc