Parse error at Function:usage might be invalid syntax
7 ビュー (過去 30 日間)
古いコメントを表示
Can anyone tell me why I am getting a "Parse error at Function" message? The message in question is on the bottom of this image.
0 件のコメント
回答 (2 件)
Walter Roberson
2016 年 10 月 26 日
You need an 'end' statement before that 'function', to match the 'function' on your first line (but which we cannot see in the picture). You have used an 'end' for the 'function' that we can see, and you have to be consistent about using (or not using) 'end' with every function in a .m file.
1 件のコメント
Benjamin Azrieli
2020 年 11 月 23 日
編集済み: Benjamin Azrieli
2020 年 11 月 23 日
This was the solution for me when I encountered the same issue with functions in my script. I was working on a for-loop in the script and tried to use the function, located in the same script, in the command line without putting an end on the unfinished for-loop. Adding an end statement worked perfectly, thank you Walter.
James Tursa
2016 年 10 月 26 日
編集済み: James Tursa
2016 年 10 月 26 日
Very hard to read your pic of the code (in the future, post the actual code and not a picture), but from the looks of it you have defined your own function named "eq". This is a very poor choice for a user-defined function name since that is the name of the MATLAB operator ==. So my guess is you are shadowing the MATLAB == operator with your eq function. Try picking a different name for your eq function, e.g. "myequation" or something else, and then see what errors you are getting with your code.
doc eq
And "error" is the name of another existing MATLAB function, so my advice is to use another name for that variable as well.
Finally, is this code part of a script file or a function file? If it is a script file, your version of MATLAB may not allow you to define functions within that file (i.e., your "eq" function). So you would need to put your "eq" function code (renamed to "myfunction" of course!) in a separate file.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!