matlab运行出现问题,Attempted to access e(1,0); index must be a pos
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/16 17:05:02
matlab运行出现问题,Attempted to access e(1,0); index must be a positive integer or logical.
高手帮我看看以下程序吧,dijkstra算法,记录任意两点之间的最短路径,if netCostMatrix(t,farthestPreviousHop(t)) < netCostMatrix(t,p) 在这行出现问题
function [path,totalCost,farthestPreviousHop,farthestNextHop] = dijkstra_1(n,netCostMatrix,farthestPreviousHop,farthestNextHop)
visited(1:n) = 0;
distance(1:n) = inf; % it stores the shortest distance between each node and the source node;
parent(1:n) = 0;
fid=fopen('allpath.txt','w');
for s = 1:100
distance(s) = 0;
for i = 1:(n-1),
temp = [];
for h = 1:n,
if visited(h) == 0 % in the tree;
temp=[temp distance(h)];
else
temp=[temp inf];
end
end;
[t,u] = min(temp); % it starts from node with the shortest distance to the source;
visited(u) = 1; % mark it as visited;
for v = 1:n,% for each neighbors of node u;
if ( ( netCostMatrix(u,v) + distance(u)) < distance(v) )
distance(v) = distance(u) + netCostMatrix(u,v); % update the shortest distance when a shorter path is found;
parent(v) = u; % update its parent;
end;
end;
end;
for d = s:100,
path = [];
if parent(d) = 0 % if there is a path!
%path = [];
t = d;
path = [d];
while t = s
p = parent(t);
path = [p path];
if netCostMatrix(t,farthestPreviousHop(t)) < netCostMatrix(t,p)
farthestPreviousHop(t) = p;
end;
if netCostMatrix(p,farthestNextHop(p)) < netCostMatrix(p,t)
farthestNextHop(p) = t;
end;
t = p;
end;
totalCost= distance(d);
fprintf(fid,'%d ',path); %记录源点到任意一点的最短路径
end;
%allpath(d)=path;
end
fprintf(fid,'\n');
end
fclose(fid);
return;
s是起始节点,d是目标节点
令s=1时,程序没有问题,但是加上循环for s = 1:100 时,
高手帮我看看以下程序吧,dijkstra算法,记录任意两点之间的最短路径,if netCostMatrix(t,farthestPreviousHop(t)) < netCostMatrix(t,p) 在这行出现问题
function [path,totalCost,farthestPreviousHop,farthestNextHop] = dijkstra_1(n,netCostMatrix,farthestPreviousHop,farthestNextHop)
visited(1:n) = 0;
distance(1:n) = inf; % it stores the shortest distance between each node and the source node;
parent(1:n) = 0;
fid=fopen('allpath.txt','w');
for s = 1:100
distance(s) = 0;
for i = 1:(n-1),
temp = [];
for h = 1:n,
if visited(h) == 0 % in the tree;
temp=[temp distance(h)];
else
temp=[temp inf];
end
end;
[t,u] = min(temp); % it starts from node with the shortest distance to the source;
visited(u) = 1; % mark it as visited;
for v = 1:n,% for each neighbors of node u;
if ( ( netCostMatrix(u,v) + distance(u)) < distance(v) )
distance(v) = distance(u) + netCostMatrix(u,v); % update the shortest distance when a shorter path is found;
parent(v) = u; % update its parent;
end;
end;
end;
for d = s:100,
path = [];
if parent(d) = 0 % if there is a path!
%path = [];
t = d;
path = [d];
while t = s
p = parent(t);
path = [p path];
if netCostMatrix(t,farthestPreviousHop(t)) < netCostMatrix(t,p)
farthestPreviousHop(t) = p;
end;
if netCostMatrix(p,farthestNextHop(p)) < netCostMatrix(p,t)
farthestNextHop(p) = t;
end;
t = p;
end;
totalCost= distance(d);
fprintf(fid,'%d ',path); %记录源点到任意一点的最短路径
end;
%allpath(d)=path;
end
fprintf(fid,'\n');
end
fclose(fid);
return;
s是起始节点,d是目标节点
令s=1时,程序没有问题,但是加上循环for s = 1:100 时,
nit PublicTree;
interface
uses
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,
ComCtrls,ImgList,DB,Menus;
type
TFrameTree = class(TFrame)
tvTree:TTreeView;
ImageList1:TImageList;
procedure tvTreeExpanding(Sender:TObject; Node:TTreeNode;
var AllowExpansion:Boolean);
interface
uses
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,
ComCtrls,ImgList,DB,Menus;
type
TFrameTree = class(TFrame)
tvTree:TTreeView;
ImageList1:TImageList;
procedure tvTreeExpanding(Sender:TObject; Node:TTreeNode;
var AllowExpansion:Boolean);
matlab运行出现问题,Attempted to access e(1,0); index must be a pos
MATLAB运行时:Attempted to access (1,0); index must be a positiv
Matlab问题求大神帮忙Attempted to access Xs(-17.23); index must be a
Matlab 报错为Attempted to access f(64.4); index must be a posit
运行Matlab时出现错误?Attempted to access rxd(500); index out of bou
matlab问题 Attempted to access w(1001); index out of bounds be
matlab中出现 Attempted to access X(1); index out of bounds beca
在MATLAB中,提示Attempted to access th(2,1); index out of bounds
Matlab新手,Attempted to access X(2); index out of bounds becau
matlab Attempted to access x(2); index out of bounds because
不知道为什么报这样的错:Attempted to access e(10,:); index out of bounds
Attempted to access a(:,2); index out of bounds because size