フィルターのクリア

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

116 ビュー (過去 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
  1 件のコメント
Rik
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 ExchangeWorkspace 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