MATLAB Examples

check_one_double

Test to have one double

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_double(Parameter,PropValue) tests if the PropValue value is a double. 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_double(Parameter,PropValue,Limits) is a successful test only if PropValue is included in the limits fixed by Limits.

errmsg = check_one_double(Parameter,PropValue,Limits,Accept_boundaries) allows the specification of the inclusion or the exclusion of the limit values in the acceptable range.

errmsg = check_one_double(Parameter,PropValue,Limits,Accept_boundaries,Accept_NaNs) allows the specification of an acceptable NaN value.

errmsg = check_one_double(Parameter,PropValue,Limits,Accept_boundaries,Accept_NaNs,Accept_Infs) allows the specification of an acceptable Inf value.

Input parameters

Parameter: name (string) of the parameter tested.

PropValue: value to test.

Limits: 1x2 vector of doubles. 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.

Accept_boundaries: 1x2 vector of logicals (default: [true,true]). Each element specifies if the corresponding value in Limits is acceptable.

Accept_NaNs: logical (default: true) specifying if a NaN is acceptable.

Accept_Infs: logical (default: true) specifying if a Inf is acceptable.

Output parameters

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

Examples

Test on the parameter Distance_between_points. The specification of Limits is to make sure the number given is positive (we want a positive distance). The specification of Accept_boundaries is to make sure that the minimal limit of 0 will be rejected because we use that value as denominator to compute the number of points needed in a specific length. Moreover, we need a specific value, so a NaN or a Inf should be rejected.

Distance_between_points = 0;
errmsg = check_one_double('Distance_between_points',Distance_between_points,[0 NaN],[false false],false,false);
disp(errmsg)
The parameter "Distance_between_points" must be a scalar greater than 0.

Copyright 2013 Mathieu Gendron