Tutorial

Reserved Words in MATLAB

The function iskeyword returns the reserved words of the MATLAB language.

Syntax

R = iskeyword stores in the cell array R the reserved words of the MATLAB language. tf = iskeyword(str) determines if str is a reserved word and stores the result in the logical variable tf.

% Get all reserved words
resultExample1 = iskeyword;
% Check if 'while' is a reserved word
resultExample2 = iskeyword('while');
% Check if 'name' is a reserved word
resultExample3 = iskeyword('name');
Reserved word: A special word of a programming language that cannot be used as an identifier [2].

Further reading

I recommend the following books to learn more on how reserved words are treated in MATLAB and other programming languages:

  1. MATLAB: A Practical Introduction to Programming and Problem Solving (4th Edition)

    This book was the winner of a 2017 Textbook Excellence Award. The first chapter explains MATLAB reserved words, identifiers, and other introductory topics.

  2. Concepts of Programming Languages (11th Edition)

    This book covers the fundamental topics of programming languages. Chapter 4 describes what reserved words, identifiers, variables, bindings, and scopes are in programming languages.

I also recommend the following page in the MATLAB help documentation, and the other tutorials in this series.

doc iskeyword;

Source code

I hope you have learned how to get the reserved words of the MATLAB language. The source code developed in this tutorial is available at this page.

Share

Your friends may need this knowledge to complete a task. Share this tutorial.