finding approximate indices in a monotonically increasing array
Mostra commenti meno recenti
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 Commento
Jan
il 31 Gen 2013
Please post the find command you have used, when you want us to suggest an improvement.
Risposta accettata
Più risposte (3)
Sean de Wolski
il 30 Gen 2013
[~,idx] = histc(ref,t);
Use histc() to find the bin containing ref.
1 Commento
Jan
il 31 Gen 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
il 31 Gen 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.
Categorie
Scopri di più su Creating and Concatenating Matrices in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!