Unexpected MATLAB Expression on function
显示 更早的评论
回答(2 个)
Steven Lord
2019-2-25
0 个投票
You have a couple problems with your code.
The first, as the error messages cites, is with your function definition. In a function definition, the input arguments need to be given as variable names. The inputs with which you call the function will be known by those names inside the function. What you've written is that the second input with which the user calls your EvaluateResponse function shall be known as "1" inside your code. MATLAB doesn't let you redefine numbers. Otherwise you could redefine 0 to be 1 or something similar and cause all sorts of confusion for readers of your code.
Another problem lies on line 9 of your code. Under what circumstances do you expect this "or else" clause to be executed? else statements need to be associated with and inside an if block, but this else is not. I believe you've omitted one of the if statements that should be present in your code; I'll let you determine where the missing if statement should be.
On a not really unrelated note, line 4 doesn't do anything useful. It checks if res is equal to 1 then throws away the true or false result of that comparison.
Geoff Hayes
2019-2-25
burke - it looks like your second input parameter (in the function signature) is a number. Input parameters must start with an alphabetic character.
Or, if you are trying to pass in a value of 1 for the first input parameter r, then you would call your function from the command line (or from another script or function) like
>> [res, fdb] = EvaluateResponse(1);
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
