필터 지우기
필터 지우기

In MATLAB Grader, how can I capture the printed output of a script type problem?

조회 수: 4 (최근 30일)
My understanding is that the expected way to capture the printed output of code is using evalc. I understand how I would do this for a function-type problem, but is there a name I can pass into evalc to call a learner's script for a script-type problem?
An example problem:
(a) Create a variable x=5
(b) Create a variable y=2*x, and display its value using the disp function. This should be the only output printed by your code.
I would like to be able to mark as incorrect submissions such as
x = 5
y = 2*x
disp(y)
to force students to learn how to use semicolons, etc.
I was envisioning something along the lines of
learner_output = evalc('learnerScript');
assert(strcmp(learner_output, reference_output))
  댓글 수: 3
Benjamin Walker
Benjamin Walker 2024년 3월 30일
Thank you for the suggestions - I will keep that in mind. It might come in useful for checking whether students use the colon operator or such correctly.
In my case here now that I have a working solution with evalc I think that will be the best option, especially because I don't want to make students include semicolons on lines that don't require them. Really more than semicolons it's about priming them to avoid unnecessary output to make it easier to teach the distinction between writing a function that returns a value, and writing a function that prints a value.
Dyuman Joshi
Dyuman Joshi 2024년 3월 30일
Ah, I see.
In that case, using evalc seems to be the sole option.

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

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 3월 30일
You are correct. The only way to do this in Grader is to use evalc.
For script-type problems, the learner solution is saved with the name solution.m (see here)
  댓글 수: 1
Benjamin Walker
Benjamin Walker 2024년 3월 30일
Thank you - that was exactly the info that I needed. I figured it must be in the documentation somewhere but it was a bit tucked away.
Almost as soon as I read your answer it came to me that I could use a command line
assert(false, ls)
within a test to view the file structure directly, which helped me further learn that the reference solution is stored as "+reference/solution.p", so that the full solution for what I wanted is something like
learner_output = evalc('solution');
reference_output = evalc('reference.solution')
assert(strcmp(learner_output, reference_output), "Output is incorrect")
Hopefully this is useful to anyone else trying to do something similar.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by