MATLAB: I need a help with the project!!

Hello everyone,
I have a problem writing my function on matlab and it simply shows that when I start from v(1.1)is not possible and it should be a positive integer.
it is a very simple function including a loop but it is required. this function is supposed to calculate the velocity and time for each height.
this is what I have written so far.
function y=freefall(v,t)
g=9.81;
%Gravity in m^2/s
h=input('Please Enter the hieght\n')
for k=1:h
v(k)=sqrt(2*g*k);
end
for k=1:h
t(k)=sqrt(2*k/g);
end
plot(t,v)
xlabel('Time (s)')
ylabel('Velocity
(m/s)')
title('Free fall: velocity vs time')

Best Answer

v is a vector. what do you expect v(1.1) to return? Where will the 1.1 element of that vector be found? (Between the 1st and 2nd elements, I assume, but that is not how MATLAB does indexing.)
Oh, and you spelled "height" incorrectly. :)
I'd also wonder why you pass in v and t into the function as arguments? You create both of those variables inside the function.
Instead, you should pass in h as an argument, then you would never need to use that silly input statement.
Finally, you return y as an argument from this function. But you never create y as a variable. Perhaps a better choice of arguments for the function would have been
function [v,t]=freefall(h)
now, you would use the function like this:
[v,t]=freefall(h);
and completely drop out that silly input statement.