Adding a legend manually for a plot generated by a loop
<p>I am generating a plot in Matlab one point at a time depending on how a condition is satisfied within a loop:</p>

<pre><code>for i=1:size(Ind,1)
    if(Ind(i)==1)
        c='ro';
    elseif(Ind(i)==2)
        c='bo';
    elseif(Ind(i)==3) 
        c='go';
    end
     plot(i,Y(i),c) %plotting some other value with the color chosen.
     hold on
  end
</code></pre>

<p>How do I add a legend entry to this? I want to associate the index position(1,2 and 3) to red,blue and green in the legend.</p>

<p>Thanks!</p>