MATLAB: Replace values in matrix A based on values of matrix B matrix replace values in matrix A to zero, if values in matrix B from the same position is equal to zero… Best Answer A(B==0) = 0; Related SolutionsMATLAB: Replace ‘greater than’ values in a matrix M - your matrixM(M > a) = b; MATLAB: Replacing values in a matrix based on values in a column vector Just in case anyone else has a similar problem, I found an even simpler solution.y = [2; 4; 1; 8];yMat = 1:10 == y;which produces a logical array yMat.You can get numeric values by doing:yMat = double(1:10 == y);producingyMat = 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 Related QuestionReplacing n random zeros in a matrix with a specific nonzero valueMultiplication of Sparse complex matrix and a full matrixReplace value in matrix
Best Answer