Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to delete a row and a column in a matrix?

  • To: mathgroup at
  • Subject: [mg69720] Re: How to delete a row and a column in a matrix?
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at>
  • Date: Thu, 21 Sep 2006 07:31:11 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <eeqqlr$onu$>

hussain.alqahtani at wrote:
> Dear
> I am wondering how to delete a given row and column in a matrix in a
> single command.?
> Your prompt reply is highly appreciated.

I believe that you are already aware of the Delete function. I am not 
aware of a similar function that allow simultaneously the deletion of 
rows and columns, so I wrote the following function that -- I hope -- 
should be self-explanatory and do what you are looking for.

deleteRC[(mat_)?MatrixQ, row_Integer, col_Integer] :=
   Module[{m = mat, r = row, c = col},
    If[r != 0, m = Delete[m, r]];
     If[c != 0, m = Transpose[Delete[Transpose[m],
         c]]]; m]

TableForm[m = {{a, b, c}, {d, e, f}, {j, h, k}}]

a   b   c

d   e   f

j   h   k

TableForm[deleteRC[m, 1, 3]]

d   e

j   h

TableForm[deleteRC[m, 0, 3]]

a   b

d   e

j   h


  • Prev by Date: Re: Split a file into multiple files using a pattern
  • Next by Date: does the following code shut down anyone else's kernel? - why?
  • Previous by thread: Re: How to delete a row and a column in a matrix?
  • Next by thread: could someone explain Mathematica's protests about division by zero here?