MATLAB: Error using plot, vectors must be of same length

MATLABplotting

Hi, I'm trying to use the euler method to determine the time at which a tank drains to zero. I described the equation in an m.file as seen below:
function z=eqn(h)
z=(-.5*pi*.03^2*(sqrt(19.62*h)))/(pi*(6*h-h^2));
Then I created a user function that implements the euler method on the function:
function euler1(func,h0,dt,tf)
% our time interval
t=0:dt:tf;
%setting intial y value
h(1)=h0;
for i = 1:length(t)-1
h(i+1)=h(i)+dt*(feval(func,h(i)));
if h(i+1)<0,h(i+1)=0;tdrain=t(i);break,end;
end
t=t';
h=h';
disp(tdrain)
plot(t,h);
xlabel('time')
ylabel('height')
disp(h(end))
When I run my function, it spits out a time at which the drain is emptied, however it never plots and always gives me an error stating the vectors must be of equal length. I'm very stuck, any help would be appreciated, thanks!

Best Answer

Sometimes you break out of the loop early. When you do, your t is full length but your h is short.
plot(t(1:length(h)),h)