MATLAB: Different behaviour while running Matlab script from DOS window

dos command prompt

Hi,
I have a problem starting Matlab from DOS window for different versions of Matlab.
When I call Matlab 2010bSp1 (32 bit) from DOS window to run a script, I do not see any problem.
C:\ProgramFiles\matlab\r2010bsp1\bin\matlab.exe -r "add.m"
When I call Matlab 2014a (64 bit) from DOS window to run the same script, I see a problem
C:\ProgramFiles\matlab\r2014a\bin\matlab.exe -r "add.m"
The MATLAB command window shows Undefined variable "add" or function "add.m".
Note that the path of "add.m" is not added to search path of Matlab in either case.
Can anyone please let me know why MATLAB r2014a version is not able to identify "add.m"?
Any help is highly appreciated.

Best Answer

In the R2010b timeframe, the command
add.m
would generate the error message
??? Undefined function or variable 'add'.
In R2014a the same basic message is
Undefined variable "add" or function "add.m".
By R2016a the message had become
Undefined variable "add" or class "add.m".
The difference between R2010b and R2014a reflects an underlying change in processing. In R2010b, if the function add did exist in scope, then when the syntax add.m was used, add would be invoked with no arguments, and if that did not lead to an error message itself, MATLAB would then fail trying to access the field m of the function return value (even if a structure with that field was returned) because it is not permitted in MATLAB to subsref the result of a function call. But by the time of R2014a, MATLAB's parser had been extended to examine the call as a whole and reject it as being invalid without having invoked the function add in that situation.
This does lead to a difference: in the R2010b timeframe, if the function add existed and contained a quit() or exit() call that was executed, then MATLAB would exit before it noticed that taking a structure reference off of a function return value was invalid. But in later versions, because the function would not be invoked at all in that situation, you would end up with the error message.
So, long story short: do not include the '.m' in a function call. You can include it in a run action, but not in a function call.