remove double indexvalues in loop

Hi,
I have a script where I take the maximum values out of a matrix for each column. I am using the index of the max value to get that one.
Sometimes indexmax is more then 1 value. That is the moment that i only need the highes value of A(:,e)
Now I want to avoid that i am using 2 times the same index. I want to use that index just once for the highes match.
for e = 1:length(RawDatafile)
...
for f = 1:length(CLfile)
...
for g = 1:IndRD
...
percentage = (100/length2)*length3;
A(f,e) = percentage;
end
indexmax = find(A(:,e)==max(A(:,e)));
% this is the place where i need to add a while loop or something to avoid a double used index later in the script.
%something like
%if indexmax(e) == used earlier
% use maximum highes value of (A(indexmax(e)))
%end
I tried the indexmax(1) but on that way its using just the first index and not the one he didn't use before.

5 comentarios

Is there a specific reason for not just using max with the dimensional option?
colmaxes = max(A,[],1);
Dion Theunissen
Dion Theunissen el 25 de Feb. de 2021
If i have more indices, i need to figure out which column from the first index is the highest
Just to make sure I understand, you're indicating that the max values from each column may not be unique to a specific column, and you want to know the first column that contains the max?
If this is correct, then I recommend using the expanded form of unique.
[unimaxes, ia, ic] = unique(colmaxes);
'ia' will be the indices for the first appearance of each unique max value, i.e. the first column for each max value.
Dion Theunissen
Dion Theunissen el 26 de Feb. de 2021
Sorry thats not correct, maybe a bit unclear from my side.
Usually this script works, except the case when there are in column e more from the same values. In that case indexmax can have more than 1 value. Now I have to make it that way that in the 'e loop' it will not be possible to get 2 times the same index.
So in case index = 2 and the next loop index = [2, 3] it has to take 3 cause 2 is allready been.
Ah, ok, I think I better understand now. I recommend a check to see if the value is already within indexmax.
idm = find(A(:,e)==max(A(:,e))); % Find index of max values
idm = idm(~ismember(idm,indexmax)); % Remove indices already recorded
indexmax(e) = idm(1); % Record next index

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Versión

R2020b

Etiquetas

Preguntada:

el 25 de Feb. de 2021

Comentada:

el 26 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by