Question about hard coding error
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I am using MATLAB grader and I received a message in one of the tests saying that: "it may have been that you hard coded some of the input values from the "code to call your function box". What does this error mean and how can i fix it?
Thank you
1 commentaire
Alejandro Peñuelas
le 25 Mai 2020
Hi. Hard coding happens when you define the value of a variable directly when it must be defined in the arguments of a function.
I would help if you provide some part of the source code that produces this error or even screenshots so we can help you better. Thanks.
Réponses (1)
Walter Roberson
le 25 Mai 2020
Suppose that you are required to build a function f(x,y), and you happen know it will be called with y = 19, but you write the code like
function z = f(x,y)
y = 19; %this hard-codes a value for y instead of taking it from input
z = x.^2 - y.^3;
end
You would have ignored the value that was passed into your code and would have used your own file instead.
0 commentaires
Voir également
Catégories
En savoir plus sur Software Development Tools dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!