Aptech Systems, Inc. Worldwide Headquarters
Mailing Address:
PO Box 250
Black Diamond, WA 98010 USAStreet Address:
30741 Third Avenue #160
Black Diamond, WA 98010 USAPhone: 360.886.7100
FAX: 360.886.8922Ready to Get Started?
For Pricing and Distribution
Industry Solutions
Products
Resources
Support
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?
Q&A: Register and Login
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!
Where to Buy
Available across the globe, you can have access to GAUSS no matter where you are.
Recent Tags
applications character vectors CMLMT covariance matrix dates dlibrary dllcall ECDF Editor error handling errors floating network GAUSS Engine Geometric mean graphics GUI hardware histogram hotkeys if statements installation Java API linux localization Matlab convert matlab translation matrices matrix initialization matrix manipulation Maxlik MaxLikMT Memory output pgraph graph PQG graphics RAM random numbers RedHat 6.1 simulation string functions strings threading threads loops Time Series writing dataRecent Questions
Features
Resources
delete 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.
3 Answers
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 };
//Sum the rows so 'mask'
//will be a column vector
//with non-zeros only in rows
//marked for deletion
mask = sumr(a .< 0));
//Delete rows and assign new matrix to 'xout'
xout = delif(x, mask);
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); local mask, xout; //Create a vector with 1's in //rows marked for deletion //and zeros everywhere else mask = zeros(rows(x), 1); mask[remove] = ones(rows(remove), 1); //Remove the rows and return 'xout' xout = delif(x, mask); 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.
Your request will be passed on to development.

