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.

 Respuesta aceptada

Sharan Paramasivam Murugesan
Sharan Paramasivam Murugesan el 12 de En. de 2018
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 comentarios

Jan
Jan el 12 de En. de 2018
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
Jan
Jan el 12 de En. de 2018
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 el 13 de En. de 2018
Editada: Jan el 13 de En. de 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.
Thanks Jan, great help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Community Treasure Hunt

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

Start Hunting!

Translated by