Up until recently, MATLAB had a requirement to separate scripts from functions. A file could hold one but not both types. Now, it can hold both, but functions must appear at the bottom so that it can distinguish the script parts from the function declarations.
A script is the top four lines of your code. It calls the disp() function with the argument vt. MATLAB will throw an error here because as it goes line-by-line, it discovers that vt has not yet been assigned a value.
A function is the next three, it contains the declaration term FUNCTION, the outputs, the name of the function, and the arguments to it (in parentheses). Scope determines when a variable is alive and active -- anything available to the function must be in its argument list. It need not match the script part. For instance, a variable called z in the script can be called v in the function.
To do anything interesting, you need to call the function from the script part.
z = 2;
newval = add_five(z);
function vp5 = add_five(v)
vp5 = v + 5;
Try this on for size. Note also that I'm using the elementwise multiplication operator .* to apply the operation across the entire array.
t = linspace(0,1,100);
vt = doodle(g,m,cd,t);
function vt= doodle(g,m,cd,t)