Error: Function definition are not supported in this context. Functions can only be created as local or nested functions in code files.
151 views (last 30 days)
Show older comments
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?
0 Comments
Answers (2)
Cris LaPierre
on 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.
0 Comments
Image Analyst
on 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.
0 Comments
See Also
Categories
Find more on Search Path in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!