Iterating MATLAB Commands

Some MATLAB commands can be “applied to themselves”. A good example is help help, which provides help on the help function. For what other functions fun is fun fun a legal statement that produces something interesting? Here are some examples (by no means an exhaustive list).

char char
demo demo
diary diary
doc doc
diff diff
double double
edit edit
error error
iskeyword iskeyword
length length
magic magic
max max
size size
sort sort
spy spy
unique unique
upper upper
warning warning
which which

Can you see why these are legal and guess what the effect of these calls will be? Search for “command-function duality” in the MATLAB help for some clues.

Are there any legal triple invocations? Yes, for example

and and and
char char char
isa isa isa
max max max

Indeed char can be iterated as many times as you like, but and and isa can be iterated three times but not twice.

If you think of additional interesting examples, please add them to the comments below.

2 thoughts on “Iterating MATLAB Commands

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s