I don't understand this error. "Function definitions in a script must appear at the end of the file."

Réponses (1)

I understand that you are facing an error " Function definitions in a script must appear at the end of the file."
If you are going to have a function in the same file as a script, the function definition must go at the bottom of the file.
You cannot use the structure
some script
function
some more script
It need to be like this
some script
some more script
function
The %% sections are not treated separately: the restrictions apply to the entire file, that if you have a mix of function and script then the function must go at the bottom.

2 commentaires

The odd thing was that their posted code did not have any "function" statements
Because the whole script file hasn't been shared, the screenshot could deduce us to assume only a part of the script file is shared. If the error still exists, we can work on the issue further once the whole file is shared.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by