Basic steps for you to take would be:
- Create your range up front, and not as part of the loop indexing. E.g., a t vector
- Use that range to determine the output variable size, e.g. numel(t)
- Preallocate the output variable to the size just determined. E.g., y = zeros(something,numel(t))
- Set the first y value to your initial value. E.g., y(:,1) = y0;
- Loop on an integer index, e.g. k, that will cover the number of t values
- Use that index within the loop to calculate your updated values.
For that last step, you would end up with something like this:
y(:,k+1) = y(:,k) + h * f(t(k),y(:,k));
I have used y(:,k) instead of just y(k) to allow for functions that deal with column vectors instead of just scalars.
I have left several details for you to work on. Give it a try and come back to us for more help when you need it.
When you are done, y will contain all of the intermediate values.