MATLAB: How to make all negative values in a matrix 0 columnnegative values for i= 1: size(A,1) if A (i, 2) <= 0 DataNew(i,2) = 0 This is what I have now, but there are still negative values in my DataNew matrix Best Answer %% Set all negative elements to 0A(A<0) = 0; %% Set second column elements to 0col = 2;a(a(:,col)<0,col) = 0; Related SolutionsMATLAB: Change specific matrix values to negatives B.*sign(A)or(1-(A < 0)*2).*BorB(A < 0) = -B(A < 0); MATLAB: Delete the row of matrix It's fairly basic matlab matrix manipulation. Use logical indexing:A(A(:, 1) >= 1.12 & A(:, 1) <= -1.125 & A(:, 2) >= 2.12 & A(:, 2) <= -2.3, :) = []% A(:, 1) is your X, A(:, 2) is your Y% A(:, 1) >= 1.12 & A(:, 1) <= -1.125 is all the rows of A for X in [1.12 -1.125] (1)% A(:, 2) >= 2.12 & A(:, 2) <= -2.3 is all the rows of A for Y in [2.12 -2.3] (2)% (1) & (2) is X in [1.12 -1.125] AND Y in [2.12 -2.3] % A(condition, :) = [] remove all the rows of A that fulfill the condition Related QuestionPicking rows which has negative element.Rows which do not contain zeroHow to sum specific matrix elements
Best Answer