merging two matrix into a single one

5 Ansichten (letzte 30 Tage)
Mohammad Golam Kibria
Mohammad Golam Kibria am 15 Jun. 2011
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

Akzeptierte Antwort

Matt Fig
Matt Fig am 15 Jun. 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)

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 15 Jun. 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 Kommentare
Andrei Bobrov
Andrei Bobrov am 15 Jun. 2011
L(K~=0) = K(K~=0)
Hi Mohammad! "<>" -> "~=" analog in other languages
Walter Roberson
Walter Roberson am 15 Jun. 2011
Oops... the symbolics use <> and I've been answering questions about those again.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by