Generates unique names which can be used for variables, based on the given input(s), s.


R = genvarname(s)

R = genvarname(s, exclusions)


Base input from which a unique name will be generated. Any non alpha-numeric characters will be replaced with an underscore.
Type: cell | string
Additional restrictions on names generated.
Type: cell | string


Type: cell | string


Generate unique name with a keyword as a base input:
R = genvarname('if')
R = _if

Generate unique names with a cell array of strings and no exclusions.

R = genvarname({'test','test';'test1','test'})
R =
[1,1] test
[1,2] test2
[2,1] test1
[2,2] test3
Generate unique names with cell arrays of strings and excusions:
R = genvarname({'test','test';'test1','test'}, {'test', 'test2'})
R =
[1,1] test1
[1,2] test3
[2,1] test1_1
[2,2] test4


Valid input types are strings and cell arrays of strings. For cell array inputs, the resulting output will be a cell array with unique varnames generated for each cell element. The generated names will not be keywords or built-in functions available in the current session of the application. Any non alpha-numeric characters in the input, s, are considered invalid and will be replaced with an underscore ('_'). Unique names are generated by appending the input(s) with numbers. If the input(s) start with a keyword or a number, an underscore and a number will be prepended to generate a unique name, if needed. An optional input argument exclusions, can be used to specify additional retrictions on the names generated. In such a case, the names generated will be unique to each other and the exclusions specified. exclusions must be strings or cell arrays of strings.