Azzera filtri
Azzera filtri

Zero-filling matricies but different dimensions

1 visualizzazione (ultimi 30 giorni)
Hi there,
I have two matricies A = [1 2 3; 4 5 6; 6 7 8; 11 12 13] and B = [1 2 3; 4 5 6; 11 12 13] and I would like to create a new matrix c which would be C = [1 2 3; 4 5 6; 0 0 0; 11 12 13]
I thought the following script would do it;
for i = 1:size(A); j = 1:size(B); k = 1:size(A); if B(j,:) == A(i,:); C(k,:) = B(j,:);
i = i + 1; j = j + 1; k = k + 1; else C(k,:) = [0 0 0];
i = i; j = j + 1; end end end
However, because the matricies do not have the same dimensions this is causing the computer a problem. Any ideas on what I can do with this?

Risposta accettata

Sven
Sven il 5 Feb 2013
Hi Bran,
I think this is what you're trying to do:
A = [1 2 3; 4 5 6; 6 7 8; 11 12 13]
B = [1 2 3; 4 5 6; 11 12 13]
C = A;
C(~ismember(A,B,'rows'),:) = 0
Does that work for you?
Sven.

Più risposte (0)

Categorie

Scopri di più su Graphics Object Programming 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