title: Repeating the same statement using loop
body: <p>This is the same statement for 3 times. how to do this with loop. Here, the matrix G1  dimension is 3*10. so in each part i am taking different column.</p>
  
  <pre><code>G2 = f_range_m(1:8:length(timeline_ms),:); %%%% measured range
  G1 = OrgiRange(1:8:end,:);
  
  M1 = G1(:,1);
  dist11 = abs(bsxfun( @minus,G2,M1));
  [~,col1] = min(dist11,[],2);
  Result_1 = diag(G2(:,col1));
  
  
  M2 = G1(:, 2);
  dist22 = abs(bsxfun(@minus,G2, M2));
  [~,col2] = min(dist22,[],2);
  Result_2 = diag(G2(:,col2));
  
  M3 = G1(:, 3);
  dist33 = abs(bsxfun(@minus,G2, M3));
  [~,col3] = min(dist33,[],2);
  Result_3 = diag(G2(:,col3));
  </code></pre>
  
  <p>I am trying this way. However not getting desired output. Result dimension should be 13*3.</p>
  
  <pre><code>obj = 3;
  for ix = 1:obj
      M = G1(:,ix);
      dist = abs(bsxfun(@minus,G2,M));
      [~,col] = min (dist,[],2);
      Result = diag(G2(:,col));
  end
  </code></pre>