# How to find every principal submatrix of a matrix. (given input row and column indices)

6 views (last 30 days)
Seong Park on 21 May 2023
Commented: Seong Park on 21 May 2023
I am curious as to find out how I can write so that given a square matrix, the program can compute "every" principal submatrix of the matrix.
I know how to find the basic ones; for example, given a 5x5 square matrix, finding principal submatrix by deleting same row and column. But I am struggling to find a principal matrix of let's say deleting 1st and 3rd row and column and etc.
How can I write this into a matlab code?
Thanks for any tips in advance!
##### 2 CommentsShow 1 older commentHide 1 older comment
Seong Park on 21 May 2023
the matrices that I want to use are not that large. I want the program to be set up in a way that I can use for any given size, but mainly I will be using it for less than maybe 7-by-7.
Thank you!

KSSV on 21 May 2023
You can delete 1, 3 rd row and column from 5x5 matrix using:
A = rand(5) ;
A([1 3],:) = [] ; % delete 1st and 3rd row
A(:,[1 3]) = [] ; % delete 1st and 3rd column
Seong Park on 21 May 2023
Thank you.
By principal submatrix I mean, given a matrix A, A[a] is a principal submatrix of A where a is the index.
For example, if A is a 5x5 identity matrix, A[1,2,3] = will be the matrix [1 0 0; 0 1 0; 0 0 1]. So whatever the index is, we keep that row(s) and column(s) of the original matrix and delete the rest.
Thank you!

### Categories

Find more on Matrix Indexing in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!