MATLAB: How to calculate minimum if there are more maximum values in a column

indexingMATLABmatrixmatrix array

Hello all, I am still new in MATLAB and I am a slow learner so, please your help will be appreciated.
I have a matrix 16*1, example A = [ 0.3907 0.3907 0.4650 0.2642 0.465 0.2642 0.465 0.3197 0.465 0.465 0.3197 0.465 0.3907 0.3907 0.465 0.465 ]
At the same time I have another matrix also 16*1
B = [ 0.8807 1.3866 1.5753 0.9959 1.6291 0.935 2.0934 1.1718 1.7681 2.0563 0.6348 1.4603 1.4598 1.2062 1.3946 2.0387 ] I made code as follows:
[~, idx] = max(A); Best_min = find(B == min(B([1:idx-1 idx+1:end])));
But it gives wrong answer because we have more than one maximum in matrix A. And I know that the solution done by me is perfect only when we have one maximum.
What should I do in order to find the minimum from matrix B but the rows having maximum value in A should be excluded. Thank you.

Best Answer

If I understand correctly what you want, this will work:
A = [ 0.3907 0.3907 0.4650 0.2642 0.465 0.2642 0.465 0.3197 0.465 0.465 0.3197 0.465 0.3907 0.3907 0.465 0.465 ];
B = [ 0.8807 1.3866 1.5753 0.9959 1.6291 0.935 2.0934 1.1718 1.7681 2.0563 0.6348 1.4603 1.4598 1.2062 1.3946 2.0387 ];
Amax = find(A == max(A));
Bmin = find(B == min(B));
Best_min = setdiff(Bmin,Amax); % Index Of Minimum Meeting Constraints
Best_min_mtx = [Best_min, B(Best_min)] % Index And Value For ‘B’
Best_min_mtx =
11 0.6348