Has MATLAB lost its sense of humour?

October 15th, 2010 | Categories: just for fun, math software, matlab | Tags:

MATLAB has a command called reshape that,obviously enough, allows you to reshape a matrix.

mat=rand(4)
mat =
    0.1576    0.8003    0.7922    0.8491
    0.9706    0.1419    0.9595    0.9340
    0.9572    0.4218    0.6557    0.6787
    0.4854    0.9157    0.0357    0.7577

>> reshape(mat,[2,8])
ans =
    0.1576    0.9572    0.8003    0.4218    0.7922    0.6557    0.8491    0.6787
    0.9706    0.4854    0.1419    0.9157    0.9595    0.0357    0.9340    0.7577

Obviously, the number of rows and columns both have to be positive. A negative number of rows and columns makes no sense at all. On MATLAB 2010a:

>> reshape(mat,[-2,-8])
??? Error using ==> reshape
Size vector elements should be nonnegative.

So far so boring. However, I found an old copy of MATLAB on my system (version 6.5.1) which gives much more interesting error messages

>> reshape(mat,[-2,-8])
??? Error using ==> reshape
Don't do this again!.

Obviously, I ignore the warning

>> reshape(mat,[-2,-8])
??? Error using ==> reshape
Cleve says you should be doing something more useful.

Nope, I’ve got nothing better to do

??? Error using ==> reshape
Seriously, size arguments cannot be negative.

I don’t know about you but I prefer the old error messages myself. MATLAB hasn’t completely lost its sense of humour, however, try evaluating the following for example

spy
  1. October 15th, 2010 at 22:39
    Reply | Quote | #1

    What about ‘toilet’ ?

  2. hp
    October 15th, 2010 at 23:34
    Reply | Quote | #2

    I tried ‘spy’. That is the most epic sparse matrix I’ve ever seen. No. I was wrong. It is beyond epic.

  3. October 16th, 2010 at 10:24
    Reply | Quote | #3

    Hi sander

    I remember toilet working on a previous version. Doesn’t work on my 2010a install though. Maybe I’m missing the relevant toolbox ;)

    It does, however, have a ‘shower’

  4. October 16th, 2010 at 11:06
    Reply | Quote | #4

    Try typing ‘why’ in MATLAB (minus the quotes). Each time you get a response, try the why command again.

  5. Egon
    October 16th, 2010 at 14:08
    Reply | Quote | #5

    Meh, I like MATLAB to give me the error right away; makes the debugging process that much easier. Spy and why are little niceties though.

  6. October 18th, 2010 at 10:53
    Reply | Quote | #6

    For fun, see how much you can discover about this one:
    >> image

    If all you see is a very blue upside-down boy, keep digging …

  7. October 18th, 2010 at 12:44
    Reply | Quote | #7

    Thanks for that Scott :)
    I found the dog but then ‘cheated’ and googled to get the following blog post

    http://blogs.mathworks.com/steve/2006/10/17/the-story-behind-the-matlab-default-image/

    Very cool!

  8. Matt T
    October 18th, 2010 at 15:58
    Reply | Quote | #8

    That error message is made of 17.3 metric shedloads of win. Rather reminiscent of the “don’t push this button again” message Arthur Dent gets from the Heart Of Gold.

    Does anyone else have any memories of an Easter Egg function in (probably very old*) MATLAB that… ah, had a four-lettered name that um… started with ‘f’ and er… wasn’t particularly polite? Am I misremembering? Did I just have a sys admin with a curious sense of humor?

    *would have to have been in the 90s. 94-97, I think, but who knows what version the university had at the time.

  9. October 19th, 2010 at 09:20
    Reply | Quote | #9

    Hi Matt

    I know of the possible easter egg you are referring to. Have to confess that I’ve never seen it myself though. Just tried it on 6.5.1 and no dice. I might have even older versions of MATLAB lying around…I’ll see what I can come up with :)

    Cheers,
    Mike

  10. October 21st, 2010 at 02:01

    Our “error” message for negative arguments to the “reshape” functions temporarily fixed a bug in earlier versions where negative arguments caused a segmentation violation. As our code base has increased, including such goodies in the MATLAB core has become problematic because of the strain it puts on rigorous automated testing. It is still possible to include them in a few “leaf” M functions, like “spy”, that other functions do not depend upon.

    There are a few easter eggs in the toolboxes that go with my books, NCM and EXM, http://www.mathworks.com/moler. One of the functions will help you pick apart the default “image”.

    — Cleve

  11. October 21st, 2010 at 08:25

    Hi Cleve

    Thanks for the extra background.

    Cheers,
    Mike

  12. Vincent
    October 26th, 2010 at 13:47

    Once when I was a Teachers Assistant in a MATLAB programming course the students had to calculate various stuff on a 6×6 matrix representing a toxic lot. One of the things to calculate was the best placement of a straight pipe from one side to the other, such that it would go through the least amount of toxic material. Introducing interpolation and image and 3d surfaces.

    There where two girls who had figured out the loops to calculate this and wanted to know if it was “the right answer”, but rather then just say “yes, the result is 14 to 96” or similar I told them to plot the toxic field and the pipe, and figure out for them selves if the though it was the right answer, then went on to help other students. When I came back they where continuing with other problems so I asked if they though it look correct, and one of the girls proudly replied “Yes, it’s was a baby”

    Apparently they had just written image instead of image(mat), and since the image looked like something they recognized they assumed they had solved the problem, completely forgetting all logic as to what they where doing. It took quite a while to explain to them that the correct placement of a pipe through a toxic field had nothing to do an image of a baby.