Hi Haidar,
It is my understanding that you want to perform Column Pivoting QR decomposition (CPQR) on a matrix 'X' and extract the set of pivot column indices, possibly to identify the 'r' most important columns or perform rank-revealing factorization.
In MATLAB, you can perform CPQR using the 'qr' function with an output argument for the permutation information. When you call qr with three output arguments, MATLAB returns the orthogonal matrix 'Q', the upper triangular matrix 'R', and a permutation matrix or vector 'E' that describes the column pivoting. The permutation information in 'E' tells you which columns were selected as pivots and in what order. Depending on the syntax you use, 'E' can be returned either as a permutation matrix or as a permutation vector containing the column indices directly.
To identify the first 'r' pivot columns, you can examine the diagonal entries of 'R' to determine numerical rank, or simply take the first 'r' entries of the permutation vector. The pivoting strategy in 'qr' is designed to reveal numerical rank by placing the most significant columns first. If you need more control over the rank determination or threshold, you may also want to look into the singular value decomposition (SVD) as an alternative approach for rank-revealing factorization.
You can refer to the following documentations for more information: