Question about hard coding error
조회 수: 3 (최근 30일)
이전 댓글 표시
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
Alejandro Peñuelas
2020년 5월 25일
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.
답변 (1개)
Walter Roberson
2020년 5월 25일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Software Development Tools에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!