Ask Your Question

Revision history [back]

You can use sortIdx :

    Mat x = (Mat_<float>(5, 1) << 1, 4, 2, 5, 0);
    cout << x;;
    Mat key;
    sortIdx(x, key, SORT_EVERY_COLUMN);
    for (int i = 0; i < key.rows; i++)
        cout << x.at<float>(key.at<int>(i, 0)) << "\t";

with results :

[1;
 4;
 2;
 5;
 0]

0    1       2       4       5

You can use sortIdx sortIdx :

    Mat x = (Mat_<float>(5, 1) << 1, 4, 2, 5, 0);
    cout << x;;
    Mat key;
    sortIdx(x, key, SORT_EVERY_COLUMN);
    for (int i = 0; i < key.rows; i++)
        cout << x.at<float>(key.at<int>(i, 0)) << "\t";

with results :

[1;
 4;
 2;
 5;
 0]

0    1       2       4       5