I have a [32678 x 10] matrix (`w2c`

) and I want to copy 24700 rows of it to another matrix(`out`

). I have the index of the rows to be copied in a vector(`index`

). For doing this in matlab I do:

```
out = w2c(index_im,:);
```

It takes approximately 0.002622 seconds.

In OpenCV:

```
Mat out(index.cols, w2c.cols, w2c.type());
for (int i = 0; i < index.cols; ++i) {
w2c.row(index.at<int>(i) - 1).copyTo(out.row(i));
}
```

It takes approximately 0.015121 seconds.

As you can see Matlab is 6 times faster. How can I make the OpenCV code efficient?

I am using cmake-2.9, g++-4.8, opencv-2.4.9, ubuntu 14.04

**UPDATE**:

I ran my code in release mode, here is the result ( It is still significantly slower than Matlab )

```
RELEASE DEBUG MATLAB
0.008183 0.010070 0.001604
0.009630 0.010050 0.001679
0.009120 0.009890 0.001566
0.007534 0.009567 0.001635
0.007886 0.009886 0.001840
```