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.

 Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 13 Feb. 2017

0 Stimmen

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 Kommentare

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 am 14 Feb. 2017
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 am 14 Feb. 2017
Thank you so much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Report Generator finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by