MATLAB: Exclude the maximum value per column matrixmatrix arraymatrix manipulation Hello, Consider a matrix 365 x 24. How can I exclude the maximum value per column? The final matrix will be 365 x 23 and not contain the maximum value per row. Thanks. Pavlos Best Answer This will remove the first maximum value from each row: >> M = randi(9,6,9) M = 3 9 1 1 1 1 5 2 3 9 5 2 4 6 3 8 6 4 3 1 5 8 3 2 7 8 9 5 6 7 2 1 4 2 9 1 2 7 3 9 4 2 4 7 8 4 4 2 2 5 9 8 5 1 >> R = M.'; >> [~,row] = max(R,[],1); >> col = 1:size(R,2); >> idx = sub2ind(size(R),row,col); >> N = R(setdiff(1:numel(R),idx)); >> N = reshape(N,[],size(R,2)).' N = 3 1 1 1 1 5 2 3 5 2 4 6 3 8 6 4 3 1 5 8 3 2 7 8 5 6 7 2 1 4 2 1 2 7 3 4 2 4 7 8 4 4 2 2 5 8 5 1The trick is to remember that MATLAB operates along columns first, so transposing the matrix at the start makes this whole task easier. Related SolutionsMATLAB: Help running Matlab scriptMATLAB: How to filter rows with respect to specific entry >> A=[1 2 3 4 5;0 1 2 3 4;5 6 3 2 1];>> A(A(:,3)==3,:)ans = 1 2 3 4 5 5 6 3 2 1>> Related QuestionFind how many times same element is repeatedIs it possible to extract the values with a vector of indices for each row without using the for statement from the matrixHow to flip every 5th row and column in matrixHow to combine multiple columns into a single column
Best Answer