Clear Filters
Clear Filters

Finding the columns that contain 1 and 0s(Basic Columns) in MATLAB

7 views (last 30 days)
I am attempting to create a piece of code that can identify the basic and non basic columns from a matrix. The basic columns are going to be the ones that contain only 1s and 0s, and the arrangement of the 1s must be different according to the rank of the matrix. For example, if the matrix has a rank of 2 (variable RANK), then there will be a column with a 1 in the 0th index and another column with a 1 at the 1st index. The rest of the values other than 1 will be full of 0s. Hence the number of basic columns must be equivalent to the RANK variable. The columns that are not basic will just be the non basic columns. I am unsure of the best method to code such a thing that will accurately showcase the basic and non basic columns. Note that there could be 0 basic columns or 0 non basic columns. Please get the indexes starting from 1 to identify the basic and non basic columns. In the outputs for the test cases X1 is the first column of the RREF matrix from the very left whilst X3 is the 3rd column.
A = [3 2 4;3 3 6];
RREF = rref(A)
RANK = rank(A)
Test Cases
Basic Columns: {X1, X2}
Non Basic Columns: {X3, X4, X5}
Basic Columns: {X1}
Non Basic Columns: {X2, X3, X4}
Basic Columns: {X1, X2, X3}
Non Basic Columns: {}

Accepted Answer

Matt J
Matt J on 7 Mar 2023
Edited: Matt J on 7 Mar 2023
Well, I definiitely don't think you should be using rref, which is a very primitive command. Instead , you should use this FEX download,
Note that the choice of basic columns will not be unique, in general.
A = [3 2 4;3 3 6]
A = 2×3
3 2 4 3 3 6
[X, I]=licols(A);
A_reduced = 2×3
1.0000 0 0 0 0.5000 1.0000
basiccols = 2×2
1 0 0 1
nonbasiccols = 2×1
0 0.5000

More Answers (0)


Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!