Re: Finding nearest value in a vector
- From: "Peter Bone" <peterbone@xxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 17:20:18 +0000 (UTC)
"John Chapman" <195827.remove@xxxxxxxxxx> wrote in message
<fnsv3v$3oe$1@xxxxxxxxxxxxxxxxxx>...
Hello,
I have a vector of values and I wish to find the nearest
vector element to a single variable (lookup nearest
value). I have tried using interp1 with method = 'nearest'
but as I do not have 2 vectors I am finding this does not
work. Could anyone point me in the right direction? I'm
sure this is fairly straight forward but cannot seem to
find the right command.
Thanks, John
Subtract your single variable from all elements in the array
and then abs all the elements. You're then looking for the
smallest value, which you can find using the min function.
Peter
.
- References:
- Finding nearest value in a vector
- From: John Chapman
- Finding nearest value in a vector
- Prev by Date: Re: Question aviread / imwrite
- Next by Date: Re: Inverse Laplace returns hyperbolic trig functions
- Previous by thread: Finding nearest value in a vector
- Next by thread: randn vs random number block
- Index(es):