Info
此问题已关闭。 请重新打开它进行编辑或回答。
I am getting an error in ismember function
1 次查看(过去 30 天)
显示 更早的评论
I wrote this code for dijiktras algorithm (with some modifications). When I use the ismember function I am getting the following error:
Index exceeds matrix dimensions
I know error could arise if either u or v exceeded length(scenarios) I tried my best to figure out the error but I couldnot. Please help me out here.
function [sp, spcost] = dijkstra(matrix_cost, s, d)
while sum(S)~=n
candidate=[];
for i=1:n
if S(i)==0
candidate=[candidate dist(i)];
else
candidate=[candidate inf];
end
end
[u_index u]=min(candidate);
S(u)=1;
for i=1:n
X = all(ismember(intersect(scenarios{u},Sc{u,i}),scenarios{i})); % I am getting an error here.
if((dist(u)+matrix_cost(u,i))<dist(i) && X == 1)
dist(i)=dist(u)+matriz_costo(u,i);
prev(1,i) = {u};
if counter > 1
for j=2:counter
prev(counter,i) = {NaN};
end
end
counter(i) = 1;
elseif(dist(u)+matriz_costo(u,i)) == dist(i)
prev(counter(i)+1,i) = {u};
counter(i) = counter(i)+1;
end
end
end
1 个评论
回答(1 个)
Sean de Wolski
2013-6-10
First run:
dbstop if error
Then run your code, it will stop with the debugger at the location of the error. From here you will be able to investigate all of the variables as they were when the error occured and the bug will be obvious.
My guess is that scenarios or Sc does not have u elements.
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!