merging two matrix into a single one

Hi,
I have two matrices.
j =
1 2 3
0 0 0
0 0 0
k =
0 0 0
0 0 0
4 1 7
I need the following matrix
l =
1 2 3
0 0 0
4 1 7
How to do that? Thanks

 Respuesta aceptada

Matt Fig
Matt Fig el 15 de Jun. de 2011
J = [1 2 3;0 0 0;0 0 0];
K = [0 0 0;0 0 0;4 1 7];
L = max(J,K)

Más respuestas (1)

Walter Roberson
Walter Roberson el 15 de Jun. de 2011
J = [1 2 3;0 0 0;0 0 0];
K = [0 0 0;0 0 0;4 1 7];
L = J + K;
or
L = J; L(K<>0) = K(K<>0);

5 comentarios

Mohammad Golam Kibria
Mohammad Golam Kibria el 15 de Jun. de 2011
Its also right.Thanks
Matt Fig
Matt Fig el 15 de Jun. de 2011
Walter, what is this: <>
Matt Fig
Matt Fig el 15 de Jun. de 2011
@Mohammad, the idea is that the "correct" approach might be unknown to us because of the type of example posted. Two approaches might yield the same results on one set of data and not another...
Andrei Bobrov
Andrei Bobrov el 15 de Jun. de 2011
L(K~=0) = K(K~=0)
Hi Mohammad! "<>" -> "~=" analog in other languages
Walter Roberson
Walter Roberson el 15 de Jun. de 2011
Oops... the symbolics use <> and I've been answering questions about those again.

Iniciar sesión para comentar.

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by