title: Save cv::Mat values gotten in for loop to a 2D array
body: <p>I'm a novice in c++. I want to read dcm files in a folder and concatenate the pixels of each file as a 2-D vector.
  Like...</p>
  <pre><code>
  vector img_processing(string path){
      /* 
      1. Read dcm by path.
      2. Dcm to cv::Mat.
      3. cv::Mat to vector&lt;Uint16&gt; A.
      4. return A;
      */
  }
  
  int main(){
      vector&lt;string&gt; files; // A vector contains file paths.
      vector&lt;vector&lt;Uint16&gt;&gt; array;
      for (int i = 0; i &lt; files.size(); i++){
          array.push_back(img_processing(files[i]);
      }
      // Process array...
  }
  </code></pre>
  <p>But I found that I can't get values of files except last one. So I want to know if there exists a method to keep local vector value in a for loop to an array that can be call by outside the for loop?</p>
  <p>It looked like this.
  <a href="https://i.stack.imgur.com/Mocko.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mocko.png" alt="enter image description here" /></a></p>