findIndexInOrderedVector
Index = findIndexInOrderedVector(SearchVector, operation, value, whichelement)
The output of the function is similar to certain uses of MATLAB's find() function, but is done much faster for large vectors by using binary search. An example is:
Index = find(SearchVector >= 3, 1);
This would be:
Index = findIndexInOrderedVector(SearchVector, 'geq', 3, 'first');
SearchVector is a sorted vector either ascending or descending.
operation can be equality, inequality, greater than, greater than or equal, less than, less than or equal.
value is a scalar value.
whichelement can be first or last.
As long as the operations of ==, >=, >, <=, < are available for the data type of the vector, the function should work, i.e. it can work with e.g. datetime vectors.
The function makes no assumption that the element exists. If it does not exist, it returns an empty element, i.e. isempty(Index) == true holds.
Enjoy. There may be bugs. Feel free to fix them and upload.
Cita come
Konstantinos Georgiadis (2025). findIndexInOrderedVector (https://it.mathworks.com/matlabcentral/fileexchange/69864-findindexinorderedvector), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Compatibilità della piattaforma
Windows macOS LinuxCategorie
Tag
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.
