Finding Minimum Value, Setting it only if it has not already been selected, Else Finding Next Minimum...
Ältere Kommentare anzeigen
I have a function that finds the minimum value of a row (indexed by i) and returns the row and column.
I am saving the column of the first minimum value to indx. However, I want to check before I save it, if the column number has previously been chosen, and if so, select the next minimum value.
My current code is below:
[row1,col1]=find(dst(i,:)==min(dst(i,:))); % Find the minimum value and save
the row, col
indx(i,1)=col1(1); %Select the first minimum value
So, I tried
if (unique(indx==col1(1)))~=1
% Check entire indx to see if it matches to the first minimum value chosen and if it has already been selected
indx(i,1)=col1(1); % If not, select it
else % Else find the next minimum value and select that
[row2,col2]=find(dst(i,:)==min(setdiff(dst(i,:),min(dst(i,:)))));
indx(i,1)=col2(1);
However, the (unique(indx==col1(1))) seems to fail and not working correctly.
Akzeptierte Antwort
Weitere Antworten (1)
Kategorien
Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!