title: Fast technique for normalizing a matrix in MATLAB
body: <p>I want to normalise each column of a matrix in Matlab. I have tried two implementations:</p>
  
  <p>Option A:</p>
  
  <pre><code>mx=max(x);
  mn=min(x);
  mmd=mx-mn;
  for i=1:size(x,1)
      xn(i,:)=((x(i,:)-mn+(mmd==0))./(mmd+(mmd==0)*2))*2-1; 
  end
  </code></pre>
  
  <p>Option B:</p>
  
  <pre><code>mn=mean(x);
  sdx=std(x);
  for i=1:size(x,1)
      xn(i,:)=(x(i,:)-mn)./(sdx+(sdx==0));
  end
  </code></pre>
  
  <p>However, these options take too much time for my data, e.g. 3-4 seconds on a 5000x53 matrix. Thus, is there any better solution?  </p>