MATLAB: How to replace non positive elements of matrix with a certain number replacing elements of matrix For example A=[7 4 2 1 -0.2 -3] I want to get [7 4 2 0 0 ] Best Answer max(A,0)if the replacement is to be 0 for all values less than 0.Otherwise,B = A;B(A<0) = new numberfor any other replacement number Related SolutionsMATLAB: How can i replace a matrix number with 0 A(1,3) = 0; A(3,3) = 0; MATLAB: Replace certain elements in an array Try this:N = 10; % Number of elements.States = 2*randi(2,N,1) - 3% Get the minus 1 element indexesminusOneIndexes = find(States == -1)% Get two random indexes:indexes = randperm(length(minusOneIndexes), 2);% Set them to +1indexesToChange = minusOneIndexes(indexes)States(indexesToChange) = 1 Related QuestionRemove some numbers from an array and replace them with zeroHow to replace elements of a matrix with the scaled identityHow to replace every non-0 number with the number in that place added to another number – no loopsHow to make all negative values in a matrix 0How to generate new vector and replace certain elements
Best Answer