This statement is not inside any function. (It follows the END that terminates the definition of the function "my_loadxcat_full".)
152 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Alex Mcaulley
2019-7-4
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 个评论
更多回答(2 个)
M.A.G.
2020-5-27
make sure you clear all.
1 个评论
Rik
2021-1-23
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
2021-1-23
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 个评论
Rik
2021-1-23
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!