フィルターのクリア

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 Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by