FUNCTION REFERENCE

matlab.lang.makeValidName

Turn text into valid variable names.

Turn text into valid variable names.

Syntax

N = matlab.lang.makeValidName(S)

Syntax

N = matlab.lang.makeValidName(S, 'ReplacementStyle', style, 'Prefix', prefix)

Valid names are returned unchanged. Otherwise whitespace is removed and a letter after it is capitalised; other characters that are not letters, digits or underscores are replaced by '_' (style 'underscore', the default), deleted ('delete') or written as their hexadecimal code such as 0x2D ('hex'). A name that does not start with a letter gets prefix (default 'x') in front; a keyword becomes prefix plus the capitalised keyword. Names are cut to 63 characters. S is a character vector, cellstr or string array and N has the same type and size.

Example

matlab.lang.makeValidName('12 bad name')   % 'x12BadName'

Example

matlab.lang.makeValidName({'for', 'ok_1', 'a b-c'})   % {'xFor', 'ok_1', 'aB_c'}

Example

matlab.lang.makeValidName("a-b", 'ReplacementStyle', 'delete')   % "ab"

Differences from MATLAB: no second output (modified flags).

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.