title: Adding features to plot
body: <p>I'm struggling doing the following thing:</p>
  
  <p>I did a simulation of a Stock Price, and saved the numbers in a matrix (each simulation is by columns, in row there are time instants).</p>
  
  <p>Here is the first part of the code that I used to set the parameters to simulate, I will save the trajectories in a matrix STORE_SIM</p>
  
  <pre class="lang-css prettyprint-override"><code>r=0.05 %parameters
  mu = r; sigma = 0.5; S0 = 12;
  T = 1;
  TIME = 10;
  Dt = 1/TIME;
  SIM=50
  BARR=8
  STORE_SIM=zeros(TIME+1,SIM);
  </code></pre>
  
  <p>I added an extra row to insert the starting value of the stock price S0=12 for plotting from the starting point.</p>
  
  <p>Now what I had done here is:
  <strong>if in these vectors(columns)  there is at least one one value of the vector that goes below the threshold, then save in a matrix called STORE_SIM_1</strong> (there could be more times that the price passes the threshold, but it's sufficient that was passed once.</p>
  
  <p>On the other hand, <strong>if in one of these vectors(columns), there are no values that go below the threshold, then save in a matrix called NOTACTIVE</strong></p>
  
  <pre class="lang-css prettyprint-override"><code>for i=1:SIM
  DW = sqrt(Dt)*randn(1,TIME);
  W = cumsum(DW);
  
  Strue = S0*exp((mu-0.5*sigma^2)*([Dt:Dt:T])+sigma*W);
  
  STORE_SIM(1,i)=S0
  STORE_SIM(2:TIME+1,i)=Strue
  
  
  idx = STORE_SIM&gt;BARR;
  to_del=all(idx,1);
  STORE_SIM_1=STORE_SIM;
  STORE_SIM_1(:,to_del)=0;
  
  
  index = STORE_SIM&lt;BARR
  logic=any(index)
  NOTACTIVE=STORE_SIM
  NOTACTIVE(:,logic)=0
  end
  </code></pre>
  
  <p>Now that I had done these two matrices, I plotted in the following way:</p>
  
  <pre class="lang-css prettyprint-override"><code>figure(1)
  hold on
  xlim([1 12])
  for i=1:SIM
  plot(NOTACTIVE(:,i),'--')
  end
  hold on
  for i=1:SIM
      plot(STORE_SIM_1(:,i),'k')
  end
  hold on
  plot([1,12],[8,8],'r','LineWidth',3)
  </code></pre>
  
  <p>Now what I'd like to do is to add to this plot some red lines representing each one <strong>the first time that a value in the vector(column) went beyond the threshold</strong>.</p>
  
  <ol>
  <li>I don't know how to set a matrix in which I can save the row number which correspond to the first time the threshold was passed,</li>
  <li>I don't know how to add these feature to my plot in way that looks like to my picture.</li>
  </ol>
  
  <p><img src="https://i.stack.imgur.com/KuaNQ.jpg" alt="Simulated Trajectories"></p>
  
  <p>BTW. If you have suggestion on the code in general, please let me know.</p>