isvalid = isfinite(T3_All) & isfinite(Tmax_All); coeff1 = polyfit(T3_All(isvalid),Tmax_All(isvalid),1)
You would recognize it is a mask, if your professor doesn't like it, ask why, because the mo mask solution is slower and less visible.
ikeep = find(isfinite(T3_All) & isfinite(Tmax_All)); coeff1 = polyfit(T3_All(ikeep),Tmax_All(ikeep),1)