[Solved] Can anyone explain to me what is going on in this line of MatLAB code


y = rand(20,3); 

Creates a matrix of uniformly distributed random numbers, y.

aa= unidrnd(2,20,3) - 1;

Creates a matrix of uniformly distributed random integers, that goes from 1 to 2, and then subtract one. Thus, aa is a matrix of 0s and 1s.

val = ( aa & y<1.366e-04) | (~aa & y<8.298e-04);

This line checks all the values where aa is 1AND y<1.366e-04 OR aa is 0 AND y<8.298e-04. Note that this barely happens, being y uniformly distributed numbers from 0 to 1, being them this smalls is unlikely.

aa(val) = ~aa(val);

Take all those cases computed before, and make aa change from 0 to 1 or from 1 to 0 if it happened in that index.

6

solved Can anyone explain to me what is going on in this line of MatLAB code