title: Simplify a Matlab code involving finding the position of maximum elements of array
body: <p>I would like your help to make more efficient (maybe, by vectorising) the Matlab code below. The code below does essentially the following: take a row vector <code>A</code>;  consider the maximum elements of such a row vector and let, for example, be <code>i</code> and <code>j</code> their positions; construct two columns vectors, the first  with all zeros but a <code>1</code> positioned at <code>i</code>, the second  with all zeros but a <code>1</code> positioned at <code>j</code>. </p>
  
  <p>This is my attempt with loops, but it looks more complicated than needed.  </p>
  
  <pre><code>clear
  rng default
  A=[3 2 3];
  max_idx=ismember(A,max(A));
  vertex=cell(size(A,2),1);
  for j=1:size(max_idx,2)
      if max_idx(j)&gt;0
         position=find(max_idx(j));
         vertex_temp=zeros(size(A,2),1);
         vertex_temp(position)=1;
         vertex{j}=vertex_temp;
      else
         vertex{j}=[];
      end
  end
  vertex=vertex(~cellfun('isempty',vertex)); 
  </code></pre>