So how come when I start my code with
function EA3()
I get a Error: function definitions are not permitted in this context. My friend started his code off with
function Assignment03
N=8;
L=[2 0 3 2 6 7 9 5];
.
.
.
.
I tried to mock this to play around with it but as soon as I press enter to go to line two after function it gives me that error. I have very little experience in Matlab so any help is highly appreciated. Thanks in advance.

 採用された回答

Geoff Hayes
Geoff Hayes 2017 年 2 月 13 日

0 投票

Daniel - are you sure that you are starting your code off with the line `function EA3()`? Typically, this error message is because there is some code that appears before this line. For example, if the following is saved to a file named test.m
clc;
function EA3()
% etc.
I observe the same error message.
With the exception of comments, no code can precede the function signature.

3 件のコメント

Daniel Espinoza
Daniel Espinoza 2017 年 2 月 13 日
Yeah I am 100%. I just closed MATLAB and reopened it so it can be a new start and I started off my code as
function EA()
and it gave me the same error...
%
Kelly Kearney
Kelly Kearney 2017 年 2 月 14 日
It appears that you're typing this in the Command Window, which isn't allowed. Functions need to be written in their own file. To start, type edit EA.m at the command line to create a new file; you can then put all your code in this file.
Daniel Espinoza
Daniel Espinoza 2017 年 2 月 14 日
Thank you so much!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB Report Generator についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by