title: logistic regression in matlab
body: <p>i would like to implement logistic regression in matlab, i have following  few code for this</p>
  
  <pre><code>function B=logistic_regression(x,y)
  
  f=@(a)(sum(y.*log((exp(a(1)+a(2)*x)/(1+exp(a(1)+a(2)*x))))+(1-y).*log((1-((exp(a(1)+a(2)*x)/(1+exp(a(1)+a(2)*x))))))));
  a=[0.1, 0.1];
  options = optimset('PlotFcns',@optimplotfval);
  B = fminsearch(f,a, options);
  
  end
  </code></pre>
  
  <p>logistic regression is following :</p>
  
  <p>first  we are calculating logit which is equal to</p>
  
  <p>L=b0+b1*x</p>
  
  <p>then we are calculating probability which is equal to
  p=e^L/(1+e^L)</p>
  
  <p>and finally we are calculating</p>
  
  <p>y*ln(p)+(1-y)*ln(1-p)</p>
  
  <p>i decided to write  all those stuff in one line,  but when i am running code , it gives me following error</p>
  
  <pre><code>&gt;&gt; B=logistic_regression(x,y)
  Assignment has more non-singleton rhs dimensions than non-singleton subscripts
  
  Error in fminsearch (line 200)
  fv(:,1) = funfcn(x,varargin{:});
  
  Error in logistic_regression (line 6)
  B = fminsearch(f,a, options);
  </code></pre>
  
  <p>how can i  fix this problem? thanks in advance</p>