Main Content

matlab.settings.mustBeStringScalar

Validate that setting value is a string scalar

Description

matlab.settings.mustBeStringScalar(settingvalue) issues an error if settingvalue is not a string scalar. This function does not return a value.

This function ignores input arguments that are empty values. Therefore, no error is thrown when the setting value is empty.

example

Examples

collapse all

Create a setting and specify a function to validate that the setting value is a string scalar.

Create the settings group mysettings.

s = settings;
addGroup(s,'mysettings');

Add the setting MyStringSetting to mysettings and specify the validation function matlab.settings.mustBeStringScalar.

addSetting(s.mysettings,'MyStringSetting','ValidationFcn',@matlab.settings.mustBeStringScalar);

Test the validation function. Set the value of MyStringSetting to a nonstring value. As expected, MATLAB® throws an error.

s.mysettings.MyStringSetting.PersonalValue = 11;
Error setting 'MyStringSetting' in group 'mysettings': 
Value must be string or convertible to string.

Input Arguments

collapse all

Setting value to validate, specified as a scalar of one of the following:

Other data types cause an error.

Version History

Introduced in R2019b