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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by