0
votes

I want to find the index of all linear columns in matrix. The output is a vector in which gives 1 for independent columns and -1 for all linear dependency columns. For example, I have a matrix A that is

A =

     1     0     0     0     0     1   1
     1     0     0     1     0     1   1
     1     1     1     0     1     1   1
     1     1     1     0     1     1   0

We can see that column dependency are 1,2,3,5,6. Hence my expected result are

output=[-1 -1 -1 1 -1 -1 1];

And the independent matrix remains

A =

           0     1
           1     1
           0     1
           0     0

How to implement it by matlab ? How about with linear rows?

1
What if we swap col2 and col4 in the input, what would be the output then?Divakar
Sorry, I give the mistake example of column 4. Let check againuser3051460
Not sure I got the definition of "dependency" right here.Divakar
I think we can see that only col4 is linear dependency with all other col. So it will return 1 otherwise, other columns linear together (1,6) and( 2,3,5)user3051460
OK, so only unique columns? Note that this operation will reduce rank of the matrixKostya

1 Answers

1
votes

I think you are looking for something like this -

out = ones(1,size(A,2))
out(sum(all(bsxfun(@eq,A,permute(A,[1 3 2])),1),2)>=2)=-1

So, basically for each column, it finds if there are any other matching columns and if there are, it identifies that as a "dependent" (from what I could gather as the definition for this problem) column.

Output -

out =
    -1    -1    -1     1    -1    -1     1

For finding "dependency" across rows, use this -

out = ones(1,size(A,1))
out(sum(all(bsxfun(@eq,A,permute(A,[3 2 1])),2),1)>=2)=-1