iskeyword — Test MATLAB reserved keywords or list all keywords.
iskeyword(s) returns true when s is a MATLAB reserved keyword. iskeyword with no inputs returns a cell column containing the full keyword list as character vectors.
Syntax
tf = iskeyword(s)
k = iskeywordInputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
s | StringScalar | Yes | — | String scalar or character vector to test. |
Returns
| Name | Type | Description |
|---|---|---|
tf | LogicalArray | True when the text is a MATLAB keyword. |
k | Any | Cell column of MATLAB keyword character vectors. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:iskeyword:InvalidArgument | More than one input argument is supplied. | iskeyword: expected zero or one input argument |
RunMat:iskeyword:InvalidText | Input is not a string scalar or character vector. | iskeyword: input must be a string scalar or character vector |
How iskeyword works
- Accepts a string scalar or character vector for the predicate form.
- Rejects non-text inputs and nonscalar string arrays.
- The keyword list is shared with
isvarname, so reserved words such asfor,end,classdef, andparforcannot be valid variable names. - The result of
iskeyword(s)is a host logical scalar. The result ofiskeywordis a cell column of character row vectors.
Examples
Test a reserved keyword
tf = iskeyword('for')Expected output:
tf = logical(1)Test ordinary text
tf = iskeyword("plot")Expected output:
tf = logical(0)Return all keywords
k = iskeywordExpected output:
k = {'break'; 'case'; ...; 'while'}Using iskeyword with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how iskeyword changes the result.
Run a small iskeyword example, explain the result, then change one input and compare the output.
FAQ
Does iskeyword accept string arrays?⌄
Only string scalars are accepted. Multi-element string arrays are rejected so the predicate remains a scalar MATLAB-compatible query.
Is the comparison case-sensitive?⌄
Yes. MATLAB keywords are lowercase language tokens, so iskeyword('for') is true while iskeyword('For') is false.
Related Introspection functions
addprop · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · evalc · findprop · getcallinfo · inputParser · isa · ischar · isdeployed · ismethod · isobject · isstring · isUnderlyingType · keyboard · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mislocked · mlock · munlock · namelengthmax · onCleanup · stats · superclasses · underlyingType · verLessThan · version · which · who · whos
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how iskeyword is executed, line by line, in Rust.
- View the source for iskeyword in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.