# How I delete one row and one column of a matrix? [duplicate]

I think the title says it all. I am looking for a function f[A_matrix, r_Integer, c_Integer] that will return the matrix A with the row r and column c deleted. I know how to delete rows but how about columns?

Thanks, I appreciate

You are after Drop

Data example

MatrixForm[
matrx=Outer[Row@*List, CharacterRange["A", "E"], Range[5]]
]


Now you can do Drop[matrix, {row},{column}]

MatrixForm[
Drop[matrx, {3},{2}]
]


If you want to define your function

f[a_List?MatrixQ, row_Integer, column_Integer] := Drop[a, {row},{column}]

(mat = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}) // MatrixForm


del[mat_?MatrixQ, col_Integer?(Positive), row_Integer?(Positive)] :=
Module[{m = mat},
m[[All, col]] = Sequence[];
m[[row]] = Sequence[];
m
];


Now

del[mat, 1, 1] // MatrixForm


del[mat, 2, 2] // MatrixForm


• You can also assign to Nothing instead of Sequence[] Commented Feb 24, 2023 at 15:38
• @GustavoDelfino, yes, that works also. Commented Feb 24, 2023 at 15:39
• Great guys, I didn't know about this "All" thing, thank you! Commented Feb 24, 2023 at 15:40