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

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 Kommentare

Could you give us an example of a variable that is not a function handle but returns true when tested with the isa() function you shared?
Just so we're clear - this is in Matlab Grader, not in Matlab itself. But for example even typing:
f=5
in the Script in Matlab grader and submitting it passes the test.
Adam Danz
Adam Danz am 15 Jun. 2020
Bearbeitet: Adam Danz am 15 Jun. 2020
Sounds like a bug. Try this,
strcmpi(class(f),'function_handle')
Nope, still acceps f=5 alone.
However assert(isa(f,'function_handle')) seems to work. That popped up as a comment but was deleted, but I tried it anyway.
Adam Danz
Adam Danz am 15 Jun. 2020
Bearbeitet: Adam Danz am 15 Jun. 2020
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.
Weird, huh? I have no idea why it would behave this way. I'll nudge tech support. Thanks.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 15 Jun. 2020
Bearbeitet: Cris LaPierre am 15 Jun. 2020

2 Stimmen

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 Kommentare

ahhh.... thanks, Cris.
Ah, I see, this clarifies a lot, thank you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Communitys

Weitere Antworten in  Distance Learning Community

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by