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.

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.

I’ve also included a link to the results in full for more detailed perusal and the code to generate them yourself. I would love to hear of anyone’s improvements or findings!

Results – http://pastebin.com/VFe9qcjv

Source 1 – http://pastebin.com/H4Mfe9a7

Source 2 – http://pastebin.com/u1eVPcq3