How do I call an external function in Cody Coursework?

I am developing an assignment for my students in Cody Coursework.
I would like them to implement a function "f" that calls another function "g" given by me. The code for "f" would be
function [value] = f(a, b)
...
% Call g
g(a, b)
...
end
I want Cody Coursework to have access to the implementation of "g" and use it in function "f" when called.

 채택된 답변

Sharan Paramasivam Murugesan
Sharan Paramasivam Murugesan 2018년 1월 12일

2 개 추천

You can implement this function g() in a file, say, g.m and upload it in "Files Referenced" when creating a problem within the assignment.

댓글 수: 5

Francisco's comment moved here (please do no post comments in the section for answers):
Hi Sharan,
Thanks for your answer. However, I have tried this and it does not work.
Do you have any other suggestion? Am I doing something wrong?
Thank you, Kiko
Please, Francisco, explain "does not work" with any details. The answer is correct already, so better solve the actual problem you have instead of searching for alternatives.
Hi Jan,
I'm sorry if my previous question was not very specific. Here are the details of the error that I get.
1. I upload a file under the name "sum.m" in the "Files Referenced" section. The code for this function is the following:
function value = sum(a, b)
value = a + b
end
2. I implement a function f in the "Reference Solution" section. The code for this function is the following:
function value = f(a, b)
value = a + b
end
3. I implement a Test for this function, with the following code:
% Run learner solution.
a = 1;
b = 2;
value = f(a, b);
% Run reference solution.
valueRef = reference.f(a, b);
% Compare.
assessVariableEqual('value', valueRef);
4. I validate this solution by pressing "Validate Reference Solution". I obtain the following error message:
Your code could not run to completion. Please wait a few minutes, then resubmit your solution.
Assessment: Incorrect
Assessment result: incorrect
I am aware that with this implementation I am not calling the function "sum.m". I would like that this simple example worked and then I would try calling "sum" inside the function "f".
Many thanks for your help, Kiko
Jan
Jan 2018년 1월 13일
편집: Jan 2018년 1월 13일
"sum" is a bad choice as name, because this is a builtin function. Maybe "sum" is used internally for the evaluation of the result and shadowing this function causes serious troubles.
Your code does not even try to call your function sum. So why do you assume that the call of the external function is the problem? It seems like your current problem is to submit a test problem and does not concern the original question. Such changes of the problem during the discussion are confusing.
Did you select the Problem Type "function" instead of "script"? I do not know if "reference.f" is correct, because I avoid working with Cody or Code Coursework.
Thanks Jan, great help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Event Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by