FRD - Full rank factorization of input matrix X.
This will write X as the product of two matrices X = KL where both K and L have the same rank as X.
This function simply calls the MATLAB rref.m function, and then "determines" the rank of the matrix by looking at the number of zeros on the diagonal of the reduced matrix; the corresponding rows are then removed. This method has several problems. First, rref.m is not one of the computational workhorses of MATLAB. It is quite slow for large matrices. The SVD is more accurate, and faster in this case becase the SVD is built-in but RREF is an M-file (and a slow one at that). RREF is in MATLAB not for production use, but more for educational purposes. Second, looking for exact zeros is not appropriate. You should at least ensure the matrix is well-scaled, and then look for small values, not zeros. Your method is prone to errors due to trivial round-off errors.
I timed the SVD and FRD on the matrix rand(1000), which is full rank. The SVD took 19 seconds, whereas FRD took 79 seconds. The former is vastly more accurate and robust than this code, and 4 times faster.
Rounding issue is resolved.
The factorization is now based on the SVD of the input matrix.