Skip to main content
edited tags
Link
Tweeted twitter.com/StackMma/status/767186838754824192
Source Link
Akoben
  • 757
  • 5
  • 13

Remove Rows and Columns in a matrix

I know that the question of how to remove rows/columns has been asked before, but I am interested in dropping arbitrary rows and arbitrary columns, from a not necessarily square matrix.

So far, I have constructed the function:

RemoveRowsColumns[expr_, a_, b_: Null] := Module[{M},
M = Delete[expr, a];
If[b != Null, M = Delete[Transpose[M], b], 
M = Delete[Transpose[M], a]];
Transpose[M]
];

To remove a columns and b rows. This works for a square matrix provided I am removing the same rows/columns. But If I try and remove, say, rows 1,2,3 and columns 2,3,4 it doesn't give me the right answer. How can I modify it to work correctly?