Anyone can help?
I have two matrix A and B with the same size. How do I move the elements of matrix A (only with the value ==1) to matrix B. A = [1 1 0 0 ;1 1 1 0 ;0 0 0 0 ;0 0 0 0]
B = [0 0 0 0 ;0 1 1 0 ;0 1 1 1 ;0 1 0 0]
And this the matrix should be: C = [1 1 0 0 ;1 1 1 0 ;0 1 1 1 ;0 1 0 0]

답변 (1개)

KSSV
KSSV 2022년 4월 8일

0 개 추천

A = [1 1 0 0 ;1 1 1 0 ;0 0 0 0 ;0 0 0 0] ;
B = [0 0 0 0 ;0 1 1 0 ;0 1 1 1 ;0 1 0 0] ;
C = [1 1 0 0 ;1 1 1 0 ;0 1 1 1 ;0 1 0 0]
C = 4×4
1 1 0 0 1 1 1 0 0 1 1 1 0 1 0 0
iwant = B ;
iwant(A==1) = A(A==1)
iwant = 4×4
1 1 0 0 1 1 1 0 0 1 1 1 0 1 0 0
isequal(C,iwant)
ans = logical
1

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2022년 4월 8일

답변:

2022년 4월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by