# How do I call an external function in Cody Coursework?

1 view (last 30 days)
Francisco Rullan on 10 Jan 2018
Commented: Francisco Rullan on 14 Jan 2018
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.

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.

Francisco Rullan on 13 Jan 2018
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:
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 on 13 Jan 2018
"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.
Francisco Rullan on 14 Jan 2018
Thanks Jan, great help.