MATLAB: How to find in a big matrix the elements that are simultaneously min on rows and max on columns findmatrix For example I have A=rand(50,50); And I want to find the position and the values that are simultaneously min on rows and max on columns Best Answer This is very unlikely for a 5 by 5. I decreased the matrix to a 4 by 3 and it happens sometimes. Here's the code:A = randn(4, 3)[rowMins,colIndexOfMins] = min(A,[],2) % Within rows[colMaxs, rowIndexOfMaxs] = max(A,[],1) % Within columnsrowMinMap = ismember(A, rowMins)colMaxMap = ismember(A, colMaxs)itsBoth = rowMinMap & colMaxMap% Tell if there are anyif any(itsBoth(:)) [rows, cols] = find(itsBoth); for k = 1 : length(rows) message = sprintf('Row %d, column %d is both a row min and a column max',... rows(k), cols(k)); helpdlg(message); endelse message = 'No element is both a row min and a column max'; warndlg(message);endIn the command window for one case where it found such an element:A = -0.636128249660041 0.777003526719788 1.04858076053644 0.317851419059697 0.622393924172013 0.660707086367175 0.138047974449526 0.647380884516047 2.50877247318511 -0.710735074811226 -0.425631681660351 1.06345963904102rowMins = -0.636128249660041 0.317851419059697 0.138047974449526 -0.710735074811226colIndexOfMins = 1 1 1 1colMaxs = 0.317851419059697 0.777003526719788 2.50877247318511rowIndexOfMaxs = 2 1 3rowMinMap = 1 0 0 1 0 0 1 0 0 1 0 0colMaxMap = 0 1 0 1 0 0 0 0 1 0 0 0itsBoth = 0 0 0 1 0 0 0 0 0 0 0 0 Related SolutionsMATLAB: Max/Min of nonzero rows/cols 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 MATLAB: Magnitude, row and column in a Matrix Try this: A = [87.97 87.97 17.97 95.22 87.96 91.26 75.50 75.50 75.50 78.13 64.89 78.90];[MaxA,MaxRow] = max(A)[MinA,MinRow] = min(A)producing: MaxA = 95.2200 87.9700 91.2600MaxRow = 2 1 2MinA = 75.5000 64.8900 17.9700MinRow = 3 4 1 Related QuestionI have converted image into 16*16 block. How can i convert these block into videoHow to measure the aspect ratio of a certain part of an imageFind the minimum value in each row without using min
Best Answer