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

155 ビュー (過去 30 日間)
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?

回答 (2 件)

Cris LaPierre
Cris LaPierre 2023 年 3 月 29 日
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 2023 年 3 月 29 日
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.

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by