MATLAB Answers

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

2 views (last 30 days)
insaf rzig
insaf rzig on 18 Sep 2020
Commented: insaf rzig on 18 Sep 2020
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

  0 Comments

Sign in to comment.

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

Show 7 older comments
insaf rzig
insaf rzig on 18 Sep 2020
SINR =
0.8466 0.2115 0.0385 0.0243 0.2741
0.0216 0.3572 0.2595 0.1917 0.2854
0.0375 0.0141 0.0104 0.0860 0.0761
0.0354 0.0680 0.4339 0.0112 0.0443
0.0274 0.0194 0.0419 0.0347 0.0201
0.2997 0.0372 0.0238 0.4067 0.0588
0.0204 0.1418 0.0560 0.0815 0.0075
0.1020 0.0018 0.0871 0.0704 0.0091
0.0085 0.0189 0.2152 0.0321 0.1154
0.0773 0.3992 0.0755 0.2990 0.3415
mxs =
0.8466 0.3992 0.4339 0.4067 0.3415
mxinds =
1 10 4 6 10
i want to save the max value in column 2 (index 10) ,but for the column 5 ,i have to find the next max value in this column which is in (index 9) in order to remove the repetition
the matrix that i want to have shows only the maximum value in each column with different indexes
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!