BUG in nargin < 3
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
John D'Errico
le 28 Avr 2020
How is this a bug? Well, a bug in your code.
What do you expect to happen for 3 arguments? We see this test:
if nargin < 3
So if nargin ==3, then NOTHING inside the if executes. But that if statement controls the entire code inside your function.
Therefore the problem is when you call the function with 3 arguments, the output argument will never even be defined.
That is not a bug in MATLAB however. Not in any version of MATLAB.
1 commentaire
Aldo Díaz
le 29 Avr 2020
Catégories
En savoir plus sur Communications Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!