Logical arrays as indices to arrays to convert elements to zero in MATLAB -


i trying convert elements of matrix zeros depending on logical array.

suppose have random 5 x 5 matrix:

b =  0.0344    0.1869    0.7547    0.1190    0.2238 0.4387    0.4898    0.2760    0.4984    0.7513 0.3816    0.4456    0.6797    0.9597    0.2551 0.7655    0.6463    0.6551    0.3404    0.5060 0.7952    0.7094    0.1626    0.5853    0.6991 

and have array of zeros , ones same dimension:

a =   0     1     1     0     0  1     0     1     1     0  1     1     0     1     1  0     1     1     0     1  0     0     1     1     0 

doing a(logical(b)) gives me elements looking for, in vector form:

ans =  0.4387 0.3816 0.1869 0.4456 0.6463 0.7547 0.2760 0.6551 0.1626 0.4984 0.9597 0.5853 0.2551 0.5060 

how can following matrix instead?

0         0.1869    0.7547    0         0 0.4387    0         0.2760    0.4984    0.7513 0.3816    0.4456    0         0.9597    0.2551 0         0.6463    0.6551    0         0.5060 0         0         0.1626    0.5853    0 

i realized there answer in question.

setting b(~logical(a)) = 0 works.

(just keeping here because question phrased bit differently.)


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -