This statement is not inside any function. (It follows the END that terminates the definition of the function "my_loadxcat_full".)

366 次查看(过去 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);

采纳的回答

Alex Mcaulley
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

更多回答(2 个)

M.A.G.
M.A.G. 2020-5-27
make sure you clear all.
  1 个评论
Rik
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
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

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by