findInRange

Find elements within many ranges. Faster than find() for large N. Useful for PSTHs and rasterplots.
216 téléchargements
Mise à jour 21 avr. 2015

Afficher la licence

When constructing peri-event time histograms and raster-plots it's often necessary to repeatedly do the following operation:
find(X > T1 & X <= T2)
where X is a vector of the times of some measurements (eg a spike train) and T1 and T2 are the left and right edges of an event-aligned window (eg stimulus onset).
While find() is generally fast, it can get quite slow for large numbers of events/trials because it is necessary to loop over the vector of alignment-events. findInRange() uses mex to achieve much greater speeds:

X = rand(1e6,1)*1e6;
T1 = rand(1e3,1)*1e3;
T2 = T1 + 5;

tic;
V1 = findInRange(X, T1, T2);
time1 = toc;

tic;
for i=1:length(T1)
V2{i} = X(X > T1(i) & X <= T2(i));
end
time2 = toc;

time2/time1

ans =

91.3441

Citation pour cette source

Joseph O'Doherty (2024). findInRange (https://www.mathworks.com/matlabcentral/fileexchange/47864-findinrange), MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2014a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Catégories
En savoir plus sur Electrophysiology dans Help Center et MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Publié le Notes de version
1.4.0.0

Don't crash when X is a 0-by-N matrix.

1.3.0.0

Actually upload the files this time. :)

1.2.0.0

.

1.1.0.0

Bugfix for the case of X being unsorted.

1.0.0.0