There are actually two cases where you'll get a ans = display.
The first one is simply caused by the way you call your function, if you do:
then when the function ends, you'll get a display of the return value, winner since you haven't terminated the call with a semicolon. This is what happens in the screenshot you showed. To fix that, it's simple, terminate the function call with a semicolon. This has nothing to do with the function code itself:
The second problem is more subtle. In the code, you have:
Because of the typo, this is equivalent to:
You of course meant to have
Note that matlab editors actually highlights the ~ and tells you that there are two problems with the above line. As a rule, if the editor highlights something, you should investigate and fix the issue. It's usually because you've made a mistake.
The other critical section which the editor highlights is your
which again does not do what you meant. It's equivalent to:
Morale of the story: make sure that there is nothing highlighted in your code.
Best Answer