title: Matlab fit function error : Function value and YDATA sizes are not equal
body: <p>I'm trying to use the fit function to estimate a 4 parameters model(P B A R) and meet the error following message and I dont know what does it mean.</p>
  
  <pre><code>Error using fit&gt;iFit (line 367)
  Function value and YDATA sizes are not equal.
  
  Error in fit (line 108)
  [fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...
  </code></pre>
  
  <p>The basic function is </p>
  
  <pre><code>function c1 = c1(x,T,P,B,A,R)
  
  if T == 0
      c1=0;
  else
      G = @(t) 0.5*erfc((P./(4*B*R*t)).^0.5.*(B*R*x-t))...
          -1/2*(1+P*x+P*t/(B*R))*exp(P*x).*erfc((P./(4*B*R*t)).^0.5.*(B*R*x+t))...
          +(P*t/(pi*B*R)).^0.5.*exp(-P*(B*R*x-t).^2./(4*B*R*t)); %first term in the solution
      u = @(t) A*t/(B*R);%.
      v = @(t) A*(T-t)/(1-B)/R; %.
      e = @(t) 2*(u(t.*v(t))).^0.5; %.
      H1 = @(t) exp(-u(t)-v(t)).*(besseli(0,e(t))/B+besseli(1,e(t)).*((u(t)./v(t)).^0.5)/(1-B));
      GH = @(t) G(t).*H1(t);
      c1 = G(T).*exp(-A*T/(B*R))+A/R*integral(GH,0,T); %int((g*H1),0,T);
  end
  </code></pre>
  
  <p>and another function that based on the foregoing function c1 is </p>
  
  <pre><code>function cm = cm(x,time,P,B,A,R,T1)
  for i=1:length(time);
      if time(i)&lt;T1
          cm(i)=c1(x,time(i),P,B,A,R);
      else 
          cm(i)=c1(x,time(i),P,B,A,R)-c1(x,time(i)-T1,P,B,A,R);
      end
  end
  </code></pre>
  
  <p>This function mainly divide the data into two parts for different calculation. 
  I tried to give a reasonable arbitrary four parameters to run cm to obtain a set of time-c data, use the following code </p>
  
  <pre><code>x=2;
  time=0.1:0.1:10;
  T1=2;
  c=cm(x,time,0.8,0.8,0.8,0.8,T1);
  </code></pre>
  
  <p>and it works well</p>
  
  <p>after that I tried to use fit function to fit the set of data to obtain the four parameters, using the following code</p>
  
  <pre><code>ft = fittype('cm(x,time,P,B,A,R,T1)','independent','time','problem','x'); % independent variable is time, fixed parameter x
  &gt;&gt; [f, gof] = fit( time', c', ft, 'Lower', [0, 0, 0, 1,2], 'Upper', [1, 1, 1, 1,2],'problem',x);
  </code></pre>
  
  <p>thats when I met the error</p>
  
  <pre><code>Error using fit&gt;iFit (line 367)
  Function value and YDATA sizes are not equal.
  </code></pre>
  
  <p>I checked the input time-c data that obtained from function cm, they have the same size, so I don'k see anything wrong with the input data. I suspect it is the problem with the function that fit function does not work.
  Can anyone help me with this problem? Besides, what does it mean by YDATA? 
  Thank you in advance ! </p>