Info

This question is closed. Reopen it to edit or answer.

I am getting an error in ismember function

1 view (last 30 days)
jana
jana on 10 Jun 2013
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

Answers (1)

Sean de Wolski
Sean de Wolski on 10 Jun 2013
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!