MATLAB: This statement is not inside any function. (It follows the END that terminates the definition of the function “the_loadxcat_full”.)

errorMATLAB

Could you please help with explanation. Thank you in advance.
I am trying to pass a file (my_nurbs_data.txt) to my_loadxcat_full.m from my_nurbs_test.m, but I keep getting this ERROR!
Error: File: my_loadxcat_full.m Line: 16 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the function "my_loadxcat_full".)
Error in my_nurbs_test (line 5)
model = my_loadxcat_full('my_nurbs_data.txt');
my_nurbs_test.m
addpath('C:\Users\e_m20\MatLab_files');
% pass the file data to the loadxcat function
model = my_loadxcat_full('my_nurbs_data.txt');
my_loadxcat_full.m
function model = my_loadxcat_full(filename)
p=3;
fid =fopen(filename,'r');
name = fscanf(fid, '%s',1);
material = fscanf(fid, '%f',1);
composition = fscanf(fid, '%f',1);
M = fscanf(fid, '%f',inf);
N = fscanf(fid, '%f',inf);
uknots = fscanf(fid,['%f\n'],[1 N+p+1]);
vknots = fscanf(fid,['%f\n'],[1 M+p+1]);
end
fclose(fid);

Best Answer

Your last line is out of the function, you need to put it inside:
function model = my_loadxcat_full(filename)
p=3;
fid =fopen(filename,'r');
name = fscanf(fid, '%s',1);
material = fscanf(fid, '%f',1);
composition = fscanf(fid, '%f',1);
M = fscanf(fid, '%f',inf);
N = fscanf(fid, '%f',inf);
uknots = fscanf(fid,['%f\n'],[1 N+p+1]);
vknots = fscanf(fid,['%f\n'],[1 M+p+1]);
fclose(fid);
end