How can I extract specific rows based upon a logical expression?

If I have a matrix of observations, how can I create a new matrix that contains only the rows in which the   first element in the  row is greater than 0?

1 Answer



0



accepted

The GAUSS function selif will extract rows from a matrix that match a logical expression. For example:

x = { 1 3,
     -2 4,
      2 1,
      7 -9 };

mask = x[.,1] .> 0;
xout = selif(x, mask);

After the code above the variables will have the following values:

x = 
       1        3 
      -2        4 
       2        1 
       7       -9 
mask = 
       1 
       0 
       1 
       1 
xout = 
       1        3 
       2        1 
       7       -9

aptech

983

Your Answer

1 Answer

0
accepted

The GAUSS function selif will extract rows from a matrix that match a logical expression. For example:

x = { 1 3,
     -2 4,
      2 1,
      7 -9 };

mask = x[.,1] .> 0;
xout = selif(x, mask);

After the code above the variables will have the following values:

x = 
       1        3 
      -2        4 
       2        1 
       7       -9 
mask = 
       1 
       0 
       1 
       1 
xout = 
       1        3 
       2        1 
       7       -9

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

REQUEST A FREE QUOTE

Thank you for your interest in the GAUSS family of products.

© Aptech Systems, Inc. All rights reserved.

Privacy Policy | Sitemap