Question about ismember function

1 view (last 30 days)
jana
jana on 9 Jun 2013
I created a variable that stores a set of numbers for an arc (a,b). Sc{1,2} = [1,2]; Sc{2,1} = [1,2]; Sc{1,3} = [2]; Sc{3,1} = [2]; Sc{3,4} = [1,2]; Sc{4,3} = [1,2]; Sc{2,4} = [1]; Sc{4,2} = [1];
I would like to implement the following condition:
s{1} = [1,2];
for v = 1:n,
if s{v} is a subset of s{u}
s{v} = intersect( s{u},Sc{u,v});
end;
end;
I dont know how to code 'if s{v} is a subset of s{u}' in matlab. please help I tried the ismember function:
if(ismember(scenarios{v},scenarios {u}))
but it is showing the following error:
Index exceeds matrix dimensions

Answers (1)

Walter Roberson
Walter Roberson on 9 Jun 2013
That error could arise if either u or v exceeded length(s) . You have not shown us how u is being controlled, and have not shown us the relationship between "n" and length(s) .
  3 Comments
jana
jana on 9 Jun 2013
This is how u is defined:
for i = 1:(n-1),
temp = [];
for h = 1:n,
if ~visited(h) % 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) = true; % mark it as visited;
Walter Roberson
Walter Roberson on 9 Jun 2013
At the MATLAB command line give the command
dbstop if error
then run your program. When it stops with the error message, examine the values of u, and v, and size(scenarios) . Also give the command
which ismember
just in case "ismember" got overwritten as a function.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!