"Function definitions are not permitted in this context."?

I'm getting this error, but I'm not sure why. I'm using 2016a. I've attached my code file.

 採用された回答

Star Strider
Star Strider 2017 年 4 月 10 日
編集済み: Stephen23 2017 年 4 月 10 日

1 投票

In 2016a and earlier versions (I believe this changed in R2017a), you could not define functions (except anonymous functions) in a script.
The easiest solution is to create ABD.m as a function with no arguements or outputs, so:
function ABD
%%--------------- MAIN PROGRAM ---------------
... REST OF YOUR CURRENT CODE ...
end
Be sure to remember to add the final end call.
Nothing else about ‘ABD’ needs to change, except that as a function, its workspace is entirely contained within it, and will not appear in the Workspace Browser. That’s a small disadvantage, but one you can work around by simply displaying the variables you want to the Command Window. You can still call it from the Command Line as well as execute it from the Editor, since it requires no arguments.

2 件のコメント

Devin White
Devin White 2017 年 4 月 10 日
Thank you
Star Strider
Star Strider 2017 年 4 月 10 日
As always, my pleasure!
Thank you for helping me achieve 20,000 Reputation Points!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2017 年 4 月 10 日

編集済み:

2017 年 4 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by