필터 지우기
필터 지우기

Question about ismember function

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

답변 (1개)

Walter Roberson
Walter Roberson 2013년 6월 9일
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
jana
jana 2013년 6월 9일
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 2013년 6월 9일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by