t = linspace(tmin,tmax,tstep);
t is a vector.
if t<=4
MATLAB treats that as equivalent to
if all(t<=4)
and the body of the if would be executed only if no entries in t are greater than 4. But with the particular values you used for linspace() there are some values greater than 4 in t, so the if would fail.
if t>=5 && t<=7
That would be treated like
if all(t>=5 && t<=7)
which would fail for vector t because && can only be used with scalars. If you had coded
if t>=5 & t<=7
then the & operation could succeed, returning a vector of values, and the statement would be equivalent to
if all(t>=5 & t<=7)
but that would fail beause there are some values outside that range.
H0=0.2*t;
That would take all of the vector t and multiply by 0.2, and asssign the vector result to H0. But that is not going to be assigning those values to H0 selectively according to which elements in t are <= 4.
You need to proceed by using a for loop, or by putting the code into a function and using arrayfun so that you never pass in a non-scalar value. Or you need to learn how to use logical indexing. https://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html