MATLAB Examples

check_one_integer

Test to have one integer

Contents

Description

This function is to be used in the set methods of the objects to check the validity of the values specified.

errmsg = check_one_integer(Parameter,PropValue) tests if the PropValue value is an integer. It returns his result in errmsg. If the test is passed successfully, the string errmsg is empty. If the test is failed, the string errmsg specifies the error. This message includes the name Parameter.

errmsg = check_one_integer(Parameter,PropValue,limits) is a successful test only if PropValue is included in the limits fixed by limits.

Input parameters

Parameter: name (string) of the parameter tested.

PropValue: value to test.

limits: 1x2 vector of integer values. The first element is the lower accepted limit; the second element is the higher accepted limit. If a boundary does not have a limit, a NaN may be specified.

Output parameters

errmsg: Error message. It is an empty string when the test is successful.

Examples

Test on the parameter Nb_pts:

Number_of_points = 11;
errmsg = check_one_integer('Nb_pts',Number_of_points);
disp(errmsg)
Number_of_points = 5.2;
errmsg = check_one_integer('Nb_pts',Number_of_points);
disp(errmsg)
The parameter "Nb_pts" must be an integer in a double format.

Test on the parameter No_pt. The specification of limits is to make sure the number given is strictly positive.

Point_number = -8;
errmsg = check_one_integer('No_pt',Point_number,[1 NaN]);
disp(errmsg)
The parameter "No_pt" must be a scalar integer greater or equal to 1.

Copyright 2013 Mathieu Gendron