MATLAB: “A MATLAB string constant is not terminated properly”-what this error indicates?

string constant

F2= inline('(A1*(sqrt(pi)*(P1/m3)*exp(P1^2)*(erf(P1+(f2./sqrt(2/m4)))-erf(P1)))+(A2/m4)*...
(1-exp(-m3*f2-m4*(f2.*f2/2))-m3*((A1*(sqrt(pi)*(P1/m3)*exp(P1^2)*(erf(P1+(f2/sqrt(2/m4)))-erf(P1))))./A1))... +A3*(sqrt(pi)*(P2/m3)*exp(P2^2)*(erf(P2+(f2/sqrt(2/(m4+2*m1))))-erf(P2)))).*exp(m5.*f2.^2)','f2');
here only f2 is variable except this all other are constant.

Best Answer

It indicates that there is a blip too few, too many, or in the wrong place. However, you code looks ok to me.
Comments:
  • Why did you choose inline and not an anonymous function?
  • I find it easier to get strings like this one right if I split it into substrings and concatenate these in a final step
Something like this is easier to get right, to read, and to maintain.
F2 = inline( ...
[ '(A1*(sqrt(pi)*(P1/m3)*exp(P1^2)*(erf(P1+(f2./sqrt(2/m4)))' ...
, ' - erf(P1)))+(A2/m4)*(1-exp(-m3*f2-m4*(f2.*f2/2))' ...
, ' - m3*((A1*(sqrt(pi)*(P1/m3)*exp(P1^2)*(erf(P1+(f2/sqrt(2/m4)))' ...
, ' - erf(P1))))./A1))' ...
, ' + A3*(sqrt(pi)*(P2/m3)*exp(P2^2)*(erf(P2+(f2/sqrt(2/(m4+2*m1))))'...
, ' - erf(P2)))).*exp(m5.*f2.^2)' ...
] ...
, 'f2' );