Could someone please tell me how to make the following code in MATLAB more efficient? I am particularly keen to remove the for loop, as I understand that vectorizing the loop makes the program run much faster. Here ret and len are positive integers and pm is a number between 0 and 1. X is a matrix of dimensions (ret x len) and is filled with 0s and 1s at random. Basically what this piece of code does is meant to do is generate a random number between 0 and 1 for each element of the matrix X and check if the generated number is less than pm. If it is, then it replaces that element in the matrix with its ones complement. Any help would be appreciated.