MATLAB: Matrix dimensions do not agree

matrix dimensions

This is my script:
function Langner_Ue1
load data1 P v;
Vmax3 = 4;
S2 = 40-P;
Km3 = 3;
k1 = 30;
P0 = [Vmax3, Km3, k1];
lsqcurvefit(@Michaelis_Menten_Substratinhibierung_2, P0, S2, v)
figure(2)
plot(S2,v,'r*')
hold on
plot(S2,vMMI2,'r')
hold on
legend('v über S', 'MMI2 über S')
end
function MMI2 = Michaelis_Menten_Substratinhibierung_2(Vmax3, S2, Km3, k1)
MMI2 = (Vmax3.*S2)./(Km3+S2+(S2.^2./k1));
end
Matrix dimensions must agree.
Error in Langner_Ue1>Michaelis_Menten_Substratinhibierung_2 (line 40) MMI2 = (Vmax3.*S2)./(Km3+S2+(S2.^2./k1));
Error in lsqcurvefit (line 213) initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in Langner_Ue1 (line 30) lsqcurvefit(@Michaelis_Menten_Substratinhibierung_2, P0, S2, v)
Caused by: Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
If I perform the function 'Michaelis_Menten_Substratinhibierung_2' directly in the command window there is no failure and verything works fine. Why do I get a failure when I try to run the script?

Best Answer

Try this:
load data1 P v;
Vmax3 = 4;
S2 = 40-P;
Km3 = 3;
k1 = 30;
P0 = [Vmax3, Km3, k1];
P = lsqcurvefit(@Michaelis_Menten_Substratinhibierung_2, P0, S2, v);
MMI2 = Michaelis_Menten_Substratinhibierung_2(P, S2);
figure(2)
plot(S2,v,'r*')
hold on
plot(S2,vMMI2,'r')
hold on
legend('v über S', 'MMI2 über S')
end
function MMI2 = Michaelis_Menten_Substratinhibierung_2(P, S2)
Vmax3 = P(1);
Km3 = P(2);
k1 = P(3);
MMI2 = (Vmax3.*S2)./(Km3+S2+(S2.^2./k1));
end