MATLAB: Max/Min of nonzero rows/cols max/min I have a Matrix, A. I want to find the max and min for every row and column in A, excluding the zero entries. I have coded it using For loops, but it is too slow. I need it to be all vectorized. Any help is greatly appreciated. Best Answer B = A;B(B == 0) = NaN;colMax = max(B);colMin = min(B);rowMax = max(B, [], 2);rowMin = min(B, [], 2);edit: missed the bit about the zero entries Related SolutionsMATLAB: How to find maximum before a certain element in the matrix B=[5 8 5 2 6 9 10] ; [~,ind] = min(B); maxB4min = max(B(1:ind)) =8 MATLAB: Maximum of a row in a matrix Use max, and some indexing if needed:A = [...]; % some matrixN = 3; % the row that you wantmax(A(N,:)) Related QuestionHow to find largest magnitude in matrixFind the min(or max) of the 2nd row of an unknown matrixHow to set the same color scheme for two different plotsI want to find in which row the minimum element isTrim Matrix and find the min-max value the reshaped matrixMatrix question (finding the smallest number in each row)How to display in one variable the max of each one of two arrays
Best Answer