title: How to select a combination which gives me maximum accuracy of that row/combination?
body: <p><strong>I am using R2015a.</strong> I have this function which gives me the accuracy of the predicted classes using the knnclassify function. </p>
  
  <pre><code>function [acc]=knnAccuracy(sample,training,group,actual,z)
  result = knnclassify(sample, training, group, z);
  t = result';
  a = actual';
  
  count=1;
  correct=0;
  while count&lt;=size(t)
      for i=t
          k = a(count);
  
          if isequal(i,k);
              correct=correct+1;
          end
          count=count+1;
      end
  end
  b=correct(end);
  accuracy=((b./size(t))*100);
  acc=accuracy(end);
  end
  </code></pre>
  
  <p>Here, Sample Training are matrices, having an equal number of rows. The group is the associated class related to each column <a href="https://www.mathworks.com/help/bioinfo/ref/knnclassify.html/%22knnclassify()%22" rel="nofollow noreferrer">see knnclassify() for detalis</a>. This functions compares the results of the knnclassify with the actual cell array given in the function and calculates the accuracy.</p>
  
  <p>Now, I have this code which gives me all the possible combinations of the rows of the matrix inMat as follows.</p>
  
  <pre><code>inMat = magic(5); % this represent your input
  for n = 1:length(inMat)
      rowsCell = num2cell(inMat,2);
      r = nchoosek(1:size(inMat,1),n);
      out = cell2mat(reshape(rowsCell(r.',:).',n,1,[]))
  end
  </code></pre>
  
  <p>At first iteration, it gives me combinations of only 1 row than it gives me combinations of 2 rows and so on. Now on the first iteration, I will apply knnaccuracy on all combinations and then <strong>I want to select that row/combination which gives me the maximum accuracy and then I need all the possible 2-row combinations of that matrix with that certain row which we just found out which gives us a maximum accuracy.</strong> Moving on I need all three-row combinations with that specific 2-row combination which we found previously that gives the maximum sum. With each iteration, I will also check if the accuracy is increasing or not if it is decreased or remained the same I will have to stop here and At the end of the day I will consider that combination at hand to be the smallest possible combination that gives maximin accuracy.</p>