matlab中出现 Attempted to access X(1); index out of bounds because numel(X)=0.function F=nhhs1(x,y)global C %全局变量C ,X,Y都是维度为300的列向量.global Xglobal Yt=0;for i=1:1:300t=t+(C(i)/(((X(i)-x)^2+(Y(i)-y)^2)^(1/2)));F=k*t;end%mat
来源:学生作业帮助网 编辑:六六作业网 时间:2025/02/02 21:55:39
matlab中出现 Attempted to access X(1); index out of bounds because numel(X)=0.function F=nhhs1(x,y)global C %全局变量C ,X,Y都是维度为300的列向量.global Xglobal Yt=0;for i=1:1:300t=t+(C(i)/(((X(i)-x)^2+(Y(i)-y)^2)^(1/2)));F=k*t;end%mat
matlab中出现 Attempted to access X(1); index out of bounds because numel(X)=0.
function F=nhhs1(x,y)
global C %全局变量C ,X,Y都是维度为300的列向量.
global X
global Y
t=0;
for i=1:1:300
t=t+(C(i)/(((X(i)-x)^2+(Y(i)-y)^2)^(1/2)));
F=k*t;
end
%matlab报告越界,我实在是不知道为什么错了,
matlab中出现 Attempted to access X(1); index out of bounds because numel(X)=0.function F=nhhs1(x,y)global C %全局变量C ,X,Y都是维度为300的列向量.global Xglobal Yt=0;for i=1:1:300t=t+(C(i)/(((X(i)-x)^2+(Y(i)-y)^2)^(1/2)));F=k*t;end%mat
这里你不用定义全局变量
X,Y都是维度为300的列向量.如果已知直接赋值即可