Validate that input name is valid variable name
mustBeValidVariableName(varname)
example
mustBeValidVariableName(varname) validate that input name is a valid variable name. This function does not return a value.
varname
mustBeValidVariableName calls the following function to determine if the input is a valid variable name:
mustBeValidVariableName
isvarname
collapse all
Use the mustBeValidVariableName function to ensure a variable name is valid.
The saveVariable function takes a variable name as input. If the variable name is not a valid name, mustBeValidVariableName throws an error.
saveVariable
function saveVariable(fname,var) arguments fname string var string {mustBeValidVariableName} end save(fname,var); end
MATLAB® variable names cannot begin with numbers. Attempting to use 8data as a variable causes an error.
8data
v = "8data"; saveVariable("myfile",v)
Error using saveVariable Invalid argument at position 2. Value must be valid variable name(s).
Variable name, specified as a string scalar, a character vector, or cell array of character vectors.
Data Types: char | string | cell
char
string
cell
mustBeValidVariableName is designed to be used for property and function argument validation.
arguments | mustBeFile | mustBeFolder
arguments
mustBeFile
mustBeFolder