Yes, you can do that following the pattern of the linear regression fitting with little modification. In linear regression, we fit the equation
and in MATLAB we write it as
to get a and b. But since you already know slope a, your equation become
so in MATLAB use
it will give you the value of b which minimize the least square error.