how to find a vector in a known set of possibilities

1 回表示 (過去 30 日間)
Itzik Ben Shabat
Itzik Ben Shabat 2013 年 7 月 15 日
Hi, say i have a vector v that can be one of previously known 11 possibilities. is there a simple way to know which possibility it is without compairing each element? (i think its something like a lookup table but the matlab lookup table function seems to do something completely different).
for example v=[1 0 0]; possibilities=[ 0 0 1; 0 1 1; 1 0 0...] the answer to this example should be 3 (v corresponds to row 3 in the possibilities matrix)
thanks
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 15 日
How did you find 11 possibilities?

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 15 日
Use the function below to find all possibilities
function y=arrangement(v,n)
m=length(v);
y=zeros(m^n,n);
for k = 1:n
y(:,k) = repmat(reshape(repmat(v,m^(n-k),1),m*m^(n-k),1),m^(k-1),1);
end
Then write
v=[1 0];
n=3
y=arrangement(v,n)
idx=find(ismember(y,[1 0 0],'rows'))
  1 件のコメント
Itzik Ben Shabat
Itzik Ben Shabat 2013 年 7 月 15 日
find(ismember(y,[1 0 0],'rows')) is all i needed. thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by