3

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

Georgy
  • 305
  • 1
  • 7

2 Answers2

6

You are after Drop

enter image description here

Data example

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

enter image description here

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

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

enter image description here

If you want to define your function

f[a_List?MatrixQ, row_Integer, column_Integer] := Drop[a, {row},{column}]
rhermans
  • 36,518
  • 4
  • 57
  • 149
5
(mat = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}) // MatrixForm

Mathematica graphics

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

Mathematica graphics

del[mat, 2, 2] // MatrixForm

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359