How to get rid of linearly dependent columns of a given matrix on matlab

4.2k Views Asked by At

I'm having a hard time in trying to get rid of linearly dependent columns of a matrix on matlab. I was trying to run this code

for i=2:22
    if rank(D(:,1:i))==i-1
        D(:,i)=[];
    end
end 

for a 30x30 matrix with rank 22, which means that I have to get rid of 8 linearly dependent columns. In this code I am just getting rid of the first ld column and the the following one that is not ld. Does anyone know how to do that? Thanks!

1

There are 1 best solutions below

1
On BEST ANSWER

If you do not mind using matlab built-in functions:

[~,colind] = rref(A);
B = A(:, colind);