This statement is not inside any function. (It follows the END that terminates the definition of the function "my_loadxcat_full".)
152 views (last 30 days)
Show older comments
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);
0 Comments
Accepted Answer
Alex Mcaulley
on 4 Jul 2019
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
0 Comments
More Answers (2)
M.A.G.
on 27 May 2020
make sure you clear all.
1 Comment
Rik
on 23 Jan 2021
That is terrible advice. You should only have clear all once in your entire code base: as part of a script that resets Matlab entirely to the state after starting (so it essentially restarts Matlab). See the documentation for clear to see what you actually want to do. You likely want clear variables (or just clear) or clearvars.
It also isn't the solution here.
Actsfaith Castillo
on 23 Jan 2021
function x = gauss(A,B)
%This function solves Ax = b by Gauss elimination algorithm.
NA = size(A,2); [NB1,NB] = size(B);
if NB1 ~= NA, error('A and B must have compatible dimensions'); end
N = NA + NB; AB = [A(1:NA,1:NA) B(1:NA,1:NB)]; % Augmented matrix
epss = eps*ones(NA,1);
for k = 1:NA
%Scaled Partial Pivoting at AB(k,k)
[akx,kx] = max(abs(AB(k:NA,k))./max(abs([AB(k:NA,k + 1:NA) epss(1:NA - k + 1)]'))');
if akx < eps, error('Singular matrix and No unique solution'); end
mx = k + kx - 1;
if kx > 1 % Row change if necessary
tmp_row = AB(k,k:N);
AB(k,k:N) = AB(mx,k:N);
AB(mx,k:N) = tmp_row;
end
% Gauss forward elimination
AB(k,k + 1:N) = AB(k,k+1:N)/AB(k,k);
AB(k,k) = 1; %make each diagonal element one for m = k + 1: NA
AB(m,k+1:N) = AB(m,k+1:N) - AB(m,k)*AB(k,k+1:N);
AB(m,k) = 0;
end
end %backward substitution for a upper-triangular matrix equation
x(NA,:) = AB(NA,NA+1:N);
for m = NA-1:-1:1
x(m,:) = AB(m,NA + 1:N)-AB(m,m + 1:NA)*x(m + 1:NA,:);
end
1 Comment
Rik
on 23 Jan 2021
If you use the automatic indentation it will be immediately clear where you have a mismatch with end.
This also isn't an answer, but a question.
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!