merging two matrix into a single one

1 回表示 (過去 30 日間)
Mohammad Golam Kibria
Mohammad Golam Kibria 2011 年 6 月 15 日
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

採用された回答

Matt Fig
Matt Fig 2011 年 6 月 15 日
J = [1 2 3;0 0 0;0 0 0];
K = [0 0 0;0 0 0;4 1 7];
L = max(J,K)

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 6 月 15 日
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 件のコメント
Andrei Bobrov
Andrei Bobrov 2011 年 6 月 15 日
L(K~=0) = K(K~=0)
Hi Mohammad! "<>" -> "~=" analog in other languages
Walter Roberson
Walter Roberson 2011 年 6 月 15 日
Oops... the symbolics use <> and I've been answering questions about those again.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by