필터 지우기
필터 지우기

substituting, indexing two matricies

조회 수: 2 (최근 30일)
Dana
Dana 2011년 12월 14일
Hello, I have a problem that I hope someone may be able to help me with. I will try to explain it best I can. Essentially i want to substitute values from one matrix into another.
I have matrix A and B and wish to create C
A=[ 2 5 7 ; 6 8 1 ; 3 6 4 ]
B=[ 0 2 0; 4 0 0 ; 8 0 0 ]
C=[ 2 2 7 ; 4 8 1 ; 8 6 4 ]
Matrix C is the same as matrix A except every value except the zeros from matrix B has been substitued into A to create C. I hope I have expleained this properly as I am struggling to find a solution.
I have tried a few methods including loops but have not been able to find a solution.
If anyone is able to help i would be very gratefull. Thanks
Regards Dana

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 12월 14일
t = B~=0
C = A
C(t) = B(t)
  댓글 수: 1
Dana
Dana 2011년 12월 15일
Haha. Thanks andrei. That is about a thousand times simpler than what i was trying to do. Briliant. Thanks for your help. You really saved me some time

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by