【发布时间】:2016-11-19 03:45:38
【问题描述】:
我在 Matlab 中有这段代码,它应该采用翼型轮廓并增加点数,这样当我在另一个程序中绘制轮廓时,我会得到更平滑的曲线。
clear
%reading an external data file
fid = fopen('NACA0015.txt');
a = fscanf(fid,'%g %g',[2 inf]); % It has two rows now.
a = a'; % matrix transpose
n = input('200') %e.g., n=35
for i=1:n
for j=1:2
fprintf('%12.7f',a(i,j)); %a(i,1) is first column, a(i,2) is 2nd col
end
fprintf('\n');
end
fclose(fid);
for i=1:n
x(i)=a(i,1); %x , y vectors
y(i)=a(i,2);
end
% use spline to create more points
xx=0:0.01:1 % e.g., step =0.01 (number of points = (1-0)/0.01=100)
yy = spline(x,y,xx); % xx and yy are new generated values of Naca0012
fprintf('\n print spline values \n');
plot(xx,yy,'ro')
hold on
plot(x,y,'*')
当我运行它时,我得到了错误
未定义的函数或变量“x”。
读取_external_data_and_spline 时出错(第 26 行) yy = 样条(x,y,xx); % xx 和 yy 是 Naca0012 的新生成值
当 x 变量在代码中明确定义时,我完全不知道为什么这不起作用,请有人帮我解决这个问题
【问题讨论】:
-
我猜
n是0,因此创建x的循环永远不会运行,因为1:0会产生一个空数组。 -
此外,如果您在不提供输入的情况下按 Enter 键,
input会返回一个空矩阵。尝试从1:[]迭代意味着x永远不会被初始化,与1:(any number less than 1)相同。 -
我认为这不是问题,因为当我运行它时,它会在命令控制台中显示 200,然后我按 Enter 键,因此已提供输入
-
但是如果你在那行之后设置一个断点并查看
n的值,你会得到什么?