How can I find the indices where an array is closest to a certain value.
Mostrar comentarios más antiguos
I have a periodic function stored as 'discrete' points in an array, and I need to find the indices of where they cross a certain point. I can't use == because they aren't ever equal (they would be if I was representing it continuously). Here's what I tried so far but it only detects some of the points.
Vc = .1; ERR = .012;
m = size(v); term = m(1,1);
c = 1;
for i = 2:term if v(i,1) >= Vc-ERR && v(i-1,1) <= Vc+ERR inds(c,1) = i; c = c+1; end end
Can someone suggest a better method?
Respuestas (2)
Honglei Chen
el 3 de Dic. de 2012
0 votos
This may be helpful to your problem
Image Analyst
el 3 de Dic. de 2012
How about
[minValue, minIndex] = min(abs(v - Vc));
Categorías
Más información sobre Interpolation of 2-D Selections in 3-D Grids en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!