finding approximate indices in a monotonically increasing array
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I need to find the indices of an entry in a monotonically increasing array, where the value of this indices is "ref"(as shown below)
I create my increasing array "t" as follow
dt=1/10e9;
N=13600000;
t=((0:N-1)*dt);
ref=1.39459e-05;
I've already tried using the find function but it leads to incorrect results or multiple indices or no answers at all.
can anyone suggest any way I can get this working
1 commentaire
Jan
le 31 Jan 2013
Please post the find command you have used, when you want us to suggest an improvement.
Réponse acceptée
Shashank Prasanna
le 30 Jan 2013
You can use Nearest Neighbor search. If you have stats toolbox:
f = knnsearch(t',ref)
f =
139460
>> t(f)
ans =
1.39459e-05
IF you don't have the stats toolbox:
>> tri = delaunayn(t');
f = dsearchn(t',tri,ref)
f =
139460
Because you have so many points you have to be patient since it takes time.
2 commentaires
Sean de Wolski
le 31 Jan 2013
There is so much extra working put into calculating the Delaunay triangulation for all of t when all you need is a simple histogram calculation of one element! I would not recommend this approach.
Foosball?
Shashank Prasanna
le 31 Jan 2013
I agree, i just like using nearest neighbor search, and it always works. lets go.
Plus de réponses (3)
Sean de Wolski
le 30 Jan 2013
[~,idx] = histc(ref,t);
Use histc() to find the bin containing ref.
1 commentaire
Jan
le 31 Jan 2013
HISTC is a fast and efficient C-Mex function, which does not create the temporary vector abs(t - ref) and performs a binary search, which is the optimal strategy in theorie. +1
Jan
le 31 Jan 2013
dt = 10e-9;
N = 13600000;
t = (0:N-1)*dt;
ref = 1.39459e-05;
[value, index] = min(abs(t - ref));
But without doubt, the binary search of histc is smarter than comparing all values in this brute force approach.
0 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!