# delete rows of a matrix

User Forumdelete rows of a matrix

How to delete several rows of a matrix with a simple command? Suppose I want to delete rows 2, 5, 7 of a matrix.

Aptech Staff answered 4 years ago

How to delete selected rows of a matrix will depend upon why you would like to delete the rows. If you want to delete rows that match a specific logical expression, you would use the delif command. For example if you wanted to remove all rows in which there was a negative element, you could do this:

```x = { -1 0,
2 3,
3 1,
-4 2,
5 9,
6 1,
-7 2 };
//will be a column vector
//with non-zeros only in rows
//marked for deletion

//Delete rows and assign new matrix to 'xout'

After the code above xout will equal:

```
2   3
xout =   3   1
5   9
6   1
```

If you just want to delete the rows, then you could use this small procedure below.

```//Create an additive vector from 1-10
x = seqa(1, 1, 10);

//Rows to remove from 'x'
rem = { 2, 5, 7 };
xout = delRow(x, rem);

proc (1) = delRow(x, remove);
//Create a vector with 1's in
//rows marked for deletion
//and zeros everywhere else

//Remove the rows and return 'xout'
retp(xout);
endp;```

After this code above:

```      1           1
2           3
3           4
x =   4   xout =  6
5           8
6           9
7          10
8
9
10
```

I was thinking about whether there is a built-in simple command. For example, indx={2,5,7}, which collects the indices of rows to be deleted from matrix A. In Matlab, this can be simply done by "A(indx,:)=[]."  The procedure provided by using "delif" is ok (and I was using "delif", but I hate the fact that such a simple thing should call a procedure) ; I was looking for an efficient and elegant way of achieving this.

Aptech Staff answered 4 years ago

Your request will be passed on to development.

• ### Aptech Systems, Inc. Worldwide Headquarters

Aptech Systems, Inc.
2350 East Germann Road, Suite #21
Chandler, AZ 85286

Phone: 360.886.7100
FAX: 360.886.8922

• ### Training & Events

Want more guidance while learning about the full functionality of GAUSS and its capabilities? Get in touch for in-person training or browse additional references below.

• ### Tutorials

Step-by-step, informative lessons for those who want to dive into GAUSS and achieve their goals, fast.

• ### Have a Specific Question?

Get a real answer from a real person

• Need Support?
• ### Support Plans

Premier Support and Platinum Premier Support are annually renewable membership programs that provide you with important benefits including technical support, product maintenance, and substantial cost-saving features for your GAUSS System or the GAUSS Engine.

• ### User Forums

Join our community to see why our users are considered some of the most active and helpful in the industry!