findIndexInOrderedV​ector

Finds the first or last index of a SORTED vector that satisfies some (in)equality constraint with a value using binary search *FAST*
22 download
Aggiornato 1 gen 2019

Visualizza la licenza

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
Creato con R2018a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Versione Pubblicato Note della release
1.0.1

fixed bug.

1.0.0