title: MATLAB Maintaining 2 columns based on column 1 conditions
body: <p>I have  the following sample of data</p>
  
  <pre><code>Time(s)    Speed(m/s)
  1.2          7
  2.5          4.2
  2.6          8
  3.1          12
  3.6          3.2
  3.9          9.1
  4.3          1.6
  4.6          3.8
  </code></pre>
  
  <p>I want to only have the data in the time range of 2-4 seconds. I can do this no problem with </p>
  
  <pre><code>Extracted_Time_Data = Data_Times(Data_Times&gt;2 &amp; Data_Times&lt;4);
  </code></pre>
  
  <p>However I will only have the times and not the accompanying (in this case) speed value. I know I could use something like </p>
  
  <pre><code>Extracted_Speed_Data = Data(2:5,2);
  </code></pre>
  
  <p>which I could then use to make a matrix</p>
  
  <pre><code>End_Goal = [Extracted_Time_Data,Extracted_Speed_Data]
  </code></pre>
  
  <p>And I have answered my own question however what if I used another data set with hundreds of lines of data. I still want the data in the same time range <code>2-4 seconds</code> but I want MATLAB to automatically store the speed with its accompanying time.</p>
  
  <p>I hope the question is clear enough, thanks in advance for any help given.</p>