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!