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]

Réponses (1)

KSSV
KSSV le 8 Avr 2022
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

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by