When I try, I appear to get substituted values each time.
I am not sure what you mean by "the first run". Your "if L<=30" statement is true for L = 0, 10, 20, and 30, and in those cases the only action you request is Lb=L .
Perhaps your "end" for your "if" is too late? Should it be
for L=0:10:90
if L<=30
Lb=L
else
Lb=30;
end
b=L-Lb
ihr_a=subs(IHRa,La,b)
ihr_c=subs(IHRc,Lc,b)
p=ihr_a-ihr_c
end
