DocumentationHelp Center
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
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office