This is expected behavior. This error obtained is due to the change in behavior in the way that output arguments are assigned inside a M-function call.
In the newer release, you need to assign an output inside M-function, if one is requested, or throw an error if no output is available. The older release implicitly assigned [] to the output.
To work around this issue, you can return an empty value to the function output argument, as in the following example:
function y = foo(a)
disp('hello world ');
y=[];
Here is some additional information about the change in functionality:
There is a minor change from MATLAB 6.0 (R12) to MATLAB 7.0 (R14) and later in the way output arguments are assigned during a function call.
Consider the following example:
function y = foo(a)
disp('hello world');
If you execute this function in MATLAB 7.0.4 (R14SP2), you see the following result:
>> x = foo(2)
hello world
??? Output argument "y" (and maybe others) not assigned during call to "Y:\1-1UZXOV\foo.m (foo)".
Error in ==> foo at 2
disp('hello world ');
If you execute the same function in MATLAB 6.0 (R12), you see the following result:
>> x = foo(2)
hello world
Warning: One or more output arguments not assigned during call to 'foo'.
>>
Behavior that resulted in a warning in MATLAB 6.0 (R12) results in an error in MATLAB 7.0 (R14) and later versions.
Best Answer