I have a matrix that identifies the places where I want the data. For example:
N=[0,1,0,1;0,0,0,0;0,1,0,1;0,0,0,0]|
and a matrix with the same dimensions as the submatrix of N that contains only 1's (it is always a submatrix), for example
B=[1,0.8;0.8,2]
What I need to do is to have a matrix with the same dimensions as N, but with the values in B in the same place were N has ones.
so the answer should be:
BL=[0,1,0,0.8;0,0,0,0;0,0.8,0,2;0,0,0,0]
Thank you, for any advice in advance. :D

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 24 Jun. 2015
N=[0,1,0,1;0,0,0,0;0,1,0,1;0,0,0,0]
B=[1,0.8;0.8,2]
N(logical(N))=B

Weitere Antworten (1)

Adam
Adam am 24 Jun. 2015
N( N == 1 ) = B;

1 Kommentar

Assuming you're working by rows rather than columns, you may have to transpose both N and B.

Melden Sie sich an, um zu kommentieren.

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by