Azzera filtri
Azzera filtri

Matrix

2 visualizzazioni (ultimi 30 giorni)
Mate 2u
Mate 2u il 12 Apr 2012
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.

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 12 Apr 2012
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

Più risposte (1)

Wayne King
Wayne King il 12 Apr 2012
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;

Categorie

Scopri di più su Propagation and Channel Models in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by