MATLAB Answers

Jan Simon

Rare examples of confusing error messages

Asked by Jan Simon
on 23 Apr 2012

Usually Matlab creates very helpful error messages, e.g.:

 ??? Subscript indices must either be real positive integers or logicals.

It does not require much experience to identify the source of this error rapidly. (Finding a solution is completely different story!) Compared with e.g. the messages of famous operating systems or the GCC compiler, the high quality of these messages is extremely helpful.

Do you know counter-examples? Some misleading or irrelevant messages created by Matlab?


I like this question.

Jan Simon
on 17 Jan 2013

@Daniel: And I like the small number of answers. As a rough estimation 6 of 10'000 error and warning messages are not useful!

Somebody tagged this question with "almost humor". But can you image suiting tags for a similar question in a MS forum? "hate", "blunt", "rudeness", "lunacy". Therefore I think this thread points out a very good reason to use Matlab to solve problem efficiently. And therefore the certain level of humor is an evidence of the seriosity of the topic.


No products are associated with this question.

6 Answers

Answer by Andreas Goser
on 24 Apr 2012
 Accepted answer

My all-time favourite is

Caught unexpected exception of unknown type. 


Jan Simon
on 2 May 2012

@Walter: The linked solution claims: "This bug has been fixed in Release 14 Service Pack 3 (R14SP3)". Then I appreciate this service pack :-)

on 8 Jun 2012

I can generate this reliably in R2012a. Unfortunately, once I start extracting subsets of the code in the vicinity of where the problem occurs, the error goes away. The best part is there are no stack traces or other helpful information to figure out what's happening, like when MATLAB crashes outright.

S = struct('hello','world','pi',pi);

Answer by Jan Simon
on 24 Apr 2012

In Matlab5.3 (R11), but not in modern releases:

% First time:
reshape(1, [-1 -1])
  ??? Error using ==> reshape
  Don't do this again!.
% Second time:
reshape(1, [-1 -2])
  ??? Error using ==> reshape
  Cleve says you should be doing something more useful.
% Third time:
reshape(1, [-1 -3])
  ??? Error using ==> reshape
  Seriously, size argument cannot be negative.


Such eastereggs have been removed...


Too bad. Why can't people have some fun?

Answer by Daniel Shub
on 23 Apr 2012

Definitely on the irrelevant side, but luckily it was taken care of pretty quickly. I think it might be the first bug I reported to TMW.

Basically someone at TMW left a debugging message in the serial port object callback so that it would always rethrow the last warning.

  1 Comment

Jan Simon
on 23 Apr 2012

Very cute.

Answer by Oleg Komarov
on 23 Apr 2012

The guilty one:

Undefined function 'foo' for input arguments of type 'char'. 

No inputs:

Undefined function or variable 'foo'. 

Use as variable OR function?

clear foo
Undefined function or variable 'foo'. 

The two error messages considered together make you think that the first one is simply not properly behaving BECAUSE of the input.

However, most commonly it's the case of "undefined function" which is already implemented!

I suggest to suppress the first one and throw always the second message.


The question is wether the additional info causes more harm than it would if the info about the class was always omitted.

Seems to me it should look it up by function name (m-filename). So it should look for foo.m, not all possible functions of any name that take a class char (which would be a lot) and then determine if any of them are named foo.

Jan Simon
on 24 Apr 2012

It would be helpful to get one of these messages:
>> Undefined function 'foo' for input arguments of type 'char'
>> But there are these foo() functions for other inputs: ...
>> Undefined function 'foo' for input arguments of type 'char'
>> There is no other foo() function also.

Answer by Daniel Shub
on 23 Apr 2012

Another unhelpful aspect of error handling in MATLAB is if you catch an error in a callback and then rethrow the error, you lose the stack information.


Answer by Walter Roberson
on 26 Apr 2012

Invoke Error, Dispatch Exception: Exception Error Occurred

isn't the most enlightening of messages...


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!