remove double indexvalues in loop
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Bob Thompson
2021-2-26
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
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!