getting a max of a matrix without repetition of index

I have a matrix say A=[0.33 0.57 0.004 0.11; 0.39 0.01 1.00 0.003; 0.06 0.10 0.05 0.09;]
and I need max and its index of each row; which I type [MAC col]=max(A,[],2);
the results it gives me is MAC=[0.57 1.00 0.10] and col=[2 3 2].
What I need is to have col=[2 3 4] and MAC=[0.57 1.00 0.09] which has no repetition in the index "col". In this case maximum is unique for each column; if row 1 and row 3 have their maxima at a same column 2; I need MATLAB to detect which one is higher, take that as maxima of the corresponding row. for the other row the next maxima would be the answer. Does anybody know how I can do that without programming?

 Risposta accettata

A=[0.33 0.57 0.004 0.11; 0.39 0.01 1.00 0.003; 0.06 0.10 0.05 0.09;];
sz1 = size(A,1);
m = zeros(sz1,1);
idx = m;
A2 = A;
for ii = 1:sz1
[m(ii), idx(ii)] = max(A2(ii,:));
A2(:,ii) = -inf;
end

3 Commenti

No, that won't do it. suppose A=[0.06 0.10 0.05 0.09; 0.39 0.01 1.00 0.003; ;0.33 0.57 0.004 0.11];
then m=[0.10 1.00 0.33] and idx=(2,3,1). The problem is in column 2 there is another big number of 0.57; what I want in this case is m=[0.09 1.00 0.57] amd inx=[4 3 1]. it is actually a sequence. First maxima in a row... if two rows have maxima in same column; the largest number is accepted and for the other row the next maximum column is the answer, but that column should not be repeated neither.
I appreciate your help too. :)
I got it. Thanks for the idea. I fixed the code

Accedi per commentare.

Più risposte (0)

Prodotti

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by