how to find the next maximum value in column of the matrix which is different at the index of the first

4 views (last 30 days)
Hi!
I have an N * M matrix, i want to find the maximum value in each column,if the index of the first max value is the same with the others,i will find the next maximum value in those columns.
SINR =
0.3170 0.1029 0.0780 0.0014 0.0303
0.0666 0.1213 0.2206 0.4729 0.0542
0.0157 0.0109 0.2463 0.2058 0.5439
0.0404 0.1542 0.1665 0.0251 0.1449
0.0448 0.0264 0.0024 0.0532 0.0341
0.1038 0.0240 0.0028 0.1512 0.0965
0.1099 0.0503 0.2834 0.0706 0.0887
0.0324 0.2983 0.0452 0.0719 0.0344
0.4190 0.4786 0.1560 0.0094 0.0996
0.0868 0.0037 0.0024 0.1878 0.1287
SINRmax =
0.4190 0.4786 0.2834 0.4729 0.5439
0.3170 0.2983 0.2463 0.2058 0.1449
0.1099 0.1542 0.2206 0.1878 0.1287
idx1 =
9 9 7 2 3
1 8 3 3 4
7 4 2 10 10
as we see the index of the max value in column 1 is the same in column 2 ,in this case i will choose the second max value (index 8) for column 2 .
the output : put only the max value of each column and all other values at zero
0 0 0 0 0
0 0 0 0.4729 0
0 0 0 0 0.5439
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0.2834 0 0
0 0.2983 0 0 0
0.4190 0 0 0 0
0 0 0 0 0
there is a function that allows me to do that?
can you help me please

Accepted Answer

Dana
Dana on 18 Sep 2020
I'm not aware of any built-in function. You'll probably have to write one yourself. Something like:
function [mxs,mxinds] = mymax(A)
N = size(A,1);
M = size(A,2);
% allocate arrays for output
mxs = zeros(M,1);
mxinds = zeros(M,1);
% This vector will track the indices of rows that we want to consider.
% Each time we find a max in a row as we go through the columns, we'll
% remove that index from 'inds'.
inds = (1:N).';
for j = 1:M % for each column
% Find the maximum value in column j among only the rows in inds.
% Load that maximum value into mxs(j), and the corresponding
% location into the variable indj.
[mxs(j),indj] = max(A(inds,j));
% Note that indj is the location of the max within the vector
% A(inds,j), NOT the location within A(:,j). The location within
% A(:,j) is given by the following:
mxinds(j) = inds(indj);
inds(indj) = []; % delete that row index from inds
end
end
This function sequentially looks for maximums of each column starting from column 1, but where for column j we only consider rows that we have not previously identified as a maximum in any of columns 1 to j-1. I'm not sure if this is exactly what you're after. For example, if you only want to do this for columns 1 and 2, you'd need to make a modification. Or if you only wanted to exclude the row a maximum appeared in in the previous column (rather than all previous columns), you'd again have to modify things.
  10 Comments
Dana
Dana on 18 Sep 2020
When I use that value of SINR, I get
mxs =
0.8466 0.3992 0.4339 0.4067 0.2854
mxinds =
1 10 4 6 2
Are you sure you copied and pasted the function correctly?
Also, for column 5, I think index 2 is the correct answer, not 9 (0.2854 > 0.1154).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!