iskeyword

Tests whether text is a MATLAB keyword, or lists all keywords.

Category: Language Fundamentals > Entering Commands

Syntax

tf = iskeyword(s)

Returns true when s is a reserved keyword.

kw = iskeyword

Returns all keywords as a cell array of character vectors.

Description

Keywords cannot be used as variable or function names. iskeyword is useful for checking generated names, for example before building variables from column headers. The check is case sensitive, so For is not a keyword.

Input arguments

s
Character vector or string scalar to test.

Output arguments

tf
Logical scalar.
kw
Cell column listing the keywords, such as for, if, while, end.

Example

Test words

iskeyword('for')
iskeyword('x')
iskeyword('While')
Output
ans = logical
   1
ans = logical
   0
ans = logical
   0

See also

isvarname matlab.lang.makeValidName exist which