title: Find the closest weight vector to each instance in the data matrix
body: <p>Suppose I have a weight matrix <code>W</code> <strong>nxm</strong> where m is the number of variables and the n is the number of instances. Also I have data matrix <code>X</code> of the same size. I try to find the closest weight vector to each instance in X. However both matrices are so dimensional therefore plain methods are not sufficient enough. I have tried some GPU trick at MATLAB but it does not work well since it was sequential approach that was calculating the closest weight for each instance sequentially. I am now looking for efficient one shot code. That takes all the W and X and find the winner with some MATLAB tricks with possibly some GPU addition. Is there any one that can suggest any code snippet in the MATLAB?</p>
  
  <p>This is the thing that I wrote for sequential</p>
  
  <pre><code>        x_in_d = gpuArray(x_in); % take input instance to device
          W_d = gpuArray(W); % take weight matrix to device
          Dx = W_d - x_in_d(ones(size(W_d,1),1),logical(ones(1,length(x_in_d))));
          [d_min,winner] = min(sum((Dx.^2)'));
          d_min = gather(d_min); %gather results
          winner = gather(winner);
  </code></pre>