Error: Function definition are not supported in this context. Functions can only be created as local or nested functions in code files.

148 vues (au cours des 30 derniers jours)
function [mvnx] = load_mvnx('New-Session-002');
Error: Function definition are not supported in this context. Functions can only be created as local or nested functions in code files.
How do I fix this error in "load_mvnx.m" code?

Réponses (2)

Cris LaPierre
Cris LaPierre le 29 Mar 2023
You'd have to share your .m file for us to say for certain, but the error message you are getting suggests you are trying to define a function in a location where it is not allowed.
You can define functions at the bottom of a script or in their own file. See here.

Image Analyst
Image Analyst le 29 Mar 2023
You have your m-file something like this
function [mvnx] = load_mvnx('New-Session-002');
% code
end % of load_mvnx
% Now script is defined below the function definition.
clc
output = load_mvnx
when it should be like this:
clc;
filename = 'New-Session-002';
[mvnx] = load_mvnx(filename) % Call the function
% Define the function at the bottom of the m-file, below the script part.
function [mvnx] = load_mvnx(filename)
% code
end % of load_mvnx. The "end" is required if you're defining a function in a script m-file.
The script should be called something like test.m, not load_mvnx.m.

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by