필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

I am getting an error in ismember function

조회 수: 1 (최근 30일)
jana
jana 2013년 6월 10일
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개)

Sean de Wolski
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by