Question about hard coding error

10 views (last 30 days)
Bruno Fulco Mancini
Bruno Fulco Mancini on 25 May 2020
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 Comment
Alejandro Peñuelas
Alejandro Peñuelas on 25 May 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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 25 May 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.

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!