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.

This entry was posted in software and tagged . Bookmark the permalink.

2 Responses to Iterating MATLAB Commands

  1. dgroseph says:

    I was particularly inspired by this post to dig a bit further. I might have gone a bit to far, but the results are here: https://thatsgross.wordpress.com/2016/06/10/enumerating-matlab-command-iterations/

    Some highlights are:
    – union union union
    – sparse sparse sparse sparse
    – ndgrid ndgrid ndgrid ndgrid ndgrid ndgrid ndgrid ndgrid ndgrid ndgrid

    The last takes almost 20 seconds to print to the screen.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s