フィルターのクリア

Matrix

2 ビュー (過去 30 日間)
Mate 2u
Mate 2u 2012 年 4 月 12 日
I have a matrix S1 and S2 which consist of +1, -1 and 0.
I want a matrix S such that it is +1 if there is +1 in both S1 and S2. -1 if there is -1 in both S1 and S2. 0 if anything else.

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 4 月 12 日
eg
S1 = randi([-1 1],10)
S2 = randi([-1 1],10)
solution
k= S1 + S2
S = (k==2) - (k==-2)
OR
S = (S1 == 1 & S2 == 1) - (S1 == -1 & S2 == -1)
MORE variant
S = (S1 == S2).*S1
or
S = (S1 == S2).*S2

その他の回答 (1 件)

Wayne King
Wayne King 2012 年 4 月 12 日
One way
x = [1 -1; 1 -1];
y = [1 1; 1 -1];
Z= zeros(size(x));
Indx1 = find(x==1);
Indy1 = find(y==1);
Indxneg1 = find(x==-1);
Indyneg1 = find(y==-1);
Ind1 = intersect(Indx1,Indy1);
Z(Ind1) = 1;
Indneg1 = intersect(Indxneg1,Indyneg1);
Z(Indneg1) = -1;

カテゴリ

Help Center および File ExchangePropagation and Channel Models についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by