Matlab Grader - Determining if a variable is a function handle.

조회 수: 12 (최근 30일)
I'm writing a Matlab Grader assignment in which I'd like the students to define a function, say f, as a function handle. I'd then like an assessment test which verifies this. I figured an assessment test in Matlab code which simply said:
isa(f,'function_handle')
would do the job but this registers as true (in Matlab Grader) even when f is not a function handle.
  댓글 수: 7
Adam Danz
Adam Danz 2020년 6월 15일
편집: Adam Danz 2020년 6월 15일
Hmmmm..... that's fishy. So, the assert(isa(f,'function_handle')) line does throw an error when f is f=5? Why would the isa() function work when it's inside of assert() but not outside of assert()? Unfortunately I haven't used the grader and can't fiddle with it right now.
Justin Wyss-Gallifent
Justin Wyss-Gallifent 2020년 6월 15일
Weird, huh? I have no idea why it would behave this way. I'll nudge tech support. Thanks.

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

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 6월 15일
편집: Cris LaPierre 2020년 6월 15일
Assessment tests must assert the result. They do not recognize logical results as answers to the test. So the issue is not that false is being marked as correct. The isa(f,'function_handle') is returning false. It is that no assert has told Grader the result is incorrect.
Put another way, assessment tests are correct unless the code returns an error. Assert throws an error if the condition is false. So does the built-in assessVariableEqual function.
  댓글 수: 2
Adam Danz
Adam Danz 2020년 6월 15일
ahhh.... thanks, Cris.
Justin Wyss-Gallifent
Justin Wyss-Gallifent 2020년 6월 15일
Ah, I see, this clarifies a lot, thank you.

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

추가 답변 (0개)

커뮤니티

더 많은 답변 보기:  원격 교육 커뮤니티

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by