MATLAB: BUG in nargin < 3

MATLABnargin bug r2018b

Hej, I am trying to build a function with control over 3 arguments. However, I have detected a possible bug on R2018b.
The nargin control works perfectly for any number but 3!
Here you are a minimal example.
function y = myfunction(x1,x2,x3)
if nargin < 3
x3=false;
if nargin < 2
x2 = 0;
end
y = x1 + x2;
if x3
y = y/norm(y);
end
end
end

Best Answer

The example works as expected for me. It throws an error because no value is assigned to y
>> y = myfunction( 1, 2, true )
Output argument "y" (and maybe others) not assigned during call to "myfunction".
There is no else clause of the outer if-statement.
/R2018b
Related Question