Borrar filtros
Borrar filtros

Zero-filling matricies but different dimensions

1 visualización (últimos 30 días)
Bran
Bran el 5 de Feb. de 2013
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?

Respuesta aceptada

Sven
Sven el 5 de Feb. de 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.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by