Main Content

iskeyword

Determine if input is MATLAB keyword

Description

tf = iskeyword(s) returns logical 1 (true) if the input is a keyword in the MATLAB® language and logical 0 (false) otherwise. For more information about MATLAB keywords, see Keywords.

example

k = iskeyword returns a list of all MATLAB keywords.

example

Examples

collapse all

Test if the word while is a MATLAB keyword.

s = "while";
tf = iskeyword(s)
tf = logical
   1

Test if the word myStr is a MATLAB keyword.

s2 = "myStr";
tf = iskeyword(s2)
tf = logical
   0

Get a list of all MATLAB keywords.

k = iskeyword
k = 20x1 cell
    {'break'     }
    {'case'      }
    {'catch'     }
    {'classdef'  }
    {'continue'  }
    {'else'      }
    {'elseif'    }
    {'end'       }
    {'for'       }
    {'function'  }
    {'global'    }
    {'if'        }
    {'otherwise' }
    {'parfor'    }
    {'persistent'}
    {'return'    }
    {'spmd'      }
    {'switch'    }
    {'try'       }
    {'while'     }

Input Arguments

collapse all

Potential MATLAB keyword, specified as a string scalar or character vector.

Output Arguments

collapse all

True or false result, returned as a 1 or 0 of data type logical.

MATLAB keywords, returned as a cell array of character vectors.

More About

collapse all

Keywords

Keywords are identifiers in MATLAB code that have a reserved meaning, so they cannot be used as variable names. See Query MATLAB Keywords for a list of all MATLAB keywords.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a