error G0058 : index out of range when indexcat cannot find a match

I have some code that tries to find the index of an element in a vector. It then tries to assign the matches to another variable. Here is a working example:

x = { -1, 0, 1, 2, 3, 4 };
idx = indexcat(x, (x < 0));
z = x[idx];

This assigns all members of x that are less than zero to z. In this case it is only -1. If there are no matches, however, it will fail with error G0058 : index out of range. For example:

x = { 1, 2, 3, 4 };
idx = indexcat(x, (x < 0));
z = x[idx];

Is there a way for me to catch this before the error ends my program?

1 Answer


If the function indexcat cannot find a match, it will return a scalar error code. Scalar error codes in GAUSS are very much like a missing value that contains an integer error code.

For your purposes, you will just need to check the output from indexcat to see if it is something that will not work as a valid index. The GAUSS function isinfnanmiss is probably what you want to use. This function will return a 1 if the input is an infinity, a Nan or a missing value.

Here is how you could use it in your code:

x = { 1, 2, 3, 4 };
idx = indexcat(x, (x < 0));

//check to see if 'idx' contains an invalid index value
if isinfnanmiss(idx);
   //code to handle case where match
   //was not found in x
   z = x[idx];

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.


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

© Aptech Systems, Inc. All rights reserved.

Privacy Policy | Sitemap