in matlab, find the array position of an entry closest to some arbitrary value
a friend asked:
matlab question: i have an array of data. how do i get matlab to find the position of an entry closest to some arbitrary value?here's one way to solve that problem (assuming that variable k=9):
for instance, i would have
a= [1; 4; 6; 8; 12]
i want to search for 9 and have matlab spit back 4, the entry in a closest to 9.
>> [trash array_position] = min(abs(a - k))wheree array_position is the desired index value.
0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home