title: Assign labels based on given examples for a large dataset effectively
body: <p>I have matrix X (100000 X 10) and vector Y (100000 X 1). X rows are categorical and assume values 1 to 5, and labels are categorical too (11 to 20);</p>
  
  <p>The rows of X are repetitive and there are only ~25% of unique rows, I want Y to have statistical mode of all the labels for a particular unique row. </p>
  
  <p>And then there comes another dataset P (90000 X 10),  I want to predict labels Q based on the previous exercise.</p>
  
  <p>What I tried is finding unique rows of X using unique in MATLAB, and then assign statistical mode of each of these labels for the unique rows. For P, I can use ismember and carry out the same. </p>
  
  <p>The issue is in the size of the dataset and it takes an 1.5-2 hours to complete the process. Is there a vectorize version possible in MATLAB?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>[X_unique,~,ic] = unique(X,'rows','stable');
  labels=zeros(length(X_unique),1);
  for i=1:length(X_unique)
      labels(i)=mode(Y(ic==i));
  end
  
  Q=zeros(length(P),1);
  for j=1:length(X_unique)
      Q(all(repmat(X_unique(j,:),length(P),1)==P,2))=label(j);
  end
  </code></pre>