## Finding indices in an array nearest to a set of values

Finding indices in an array nearest to a set of values
# 1
07-12-2011
Finding indices in an array nearest to a set of values

I have an two arrays. One array BINDIST consists of fences. I have another array XOFFS.

Eg
I want to find to find the indices of values in XOFFS that are closest to each BINDIST.

My idea is to do as follows

I create array XMIDS such that

Then I check values in XOFFS such that

I find all XOFFS between BINDIST(1) and XMID(1), and choose among these, the closest to BINDIST(1)
Save in VALS(1)

I find all XOFFS between XMIDS(I) and XMIDS(I+1) , and choose among these, the closest to BINDIST(I+1), for I = 1 to NBINDIST-2
Save in VALS(I+1)

I find all XOFFS between XMIDS(NBINDIST-1) and BINDIST(NBINDIST) , and choose among these, the closest to BINDIST(NBINDIST)
Save in VALS(NBINDIST)

If I don't find any XOFFS if the regions described, I return ZERO to the corresponding VALS.

Result should be

Last edited by kristinu; 07-12-2011 at 07:51 PM..
 kristinu View Public Profile for kristinu Find all posts by kristinu
# 2
07-12-2011
what is the results surpposed to be?
 yinyuemi View Public Profile for yinyuemi Find all posts by yinyuemi
# 3
07-12-2011
 kristinu View Public Profile for kristinu Find all posts by kristinu
# 4
07-12-2011
try:
 yinyuemi View Public Profile for yinyuemi Find all posts by yinyuemi
# 5
07-12-2011
Coded the following csh script and got the correct result

---------- Post updated at 08:35 PM ---------- Previous update was at 08:21 PM ----------

Got no idea how this code is working. Why do you use a[x] and what's the sqrt about. You did not calculate XMIDS

Last edited by kristinu; 07-12-2011 at 10:47 PM..
 kristinu View Public Profile for kristinu Find all posts by kristinu
# 6
07-12-2011
I don't know if this codes can be run in csh, I did it in bash.

 yinyuemi View Public Profile for yinyuemi Find all posts by yinyuemi
# 7
07-12-2011
It works but trying to figure out the calculations. Values in both XOFFS and BINDIST will have both negative and positive values.
The values can be floating point, not just integers.
 kristinu View Public Profile for kristinu Find all posts by kristinu

## How to get value from array and set those values as a variable

I am new to ksh scripting, specially array. How do i get values from an array and set the value as variable and pass those variables to the different functions?? someone taught me how to get input from a file with have columns i need to read, but now i doesnt know how to set those value to be a...

## Finding compound words from a set of files from another set of files

Hi All, I am completely stuck here. I have a set of files (with names A.txt, B.txt until L.txt) which contain words like these: computer random access memory computer networking mouse terminal windows All the files from A.txt to L.txt have the same format i.e. complete words in...

## finding nearest value in a column

Hi, I have 2 files: file1: 1 ia 2 1 mn 6 1 sd 11 2 ny 3 2 ma 10 3 wa 7 3 ca 8 file2 1 mi 3 1 wi 5 2 pa 4 3 id 6

## Finding range of values in an array

I have an array containing distances in ascending order, for example: distances = 100 120 150 170 200 280 300 .... I have a number, let's say v = 170 and a variation value, let's say var = 100 . I want to return the array indexes for which the distances cover the range (v - var) to (v +...

## Help finding where certain environment variables are set

i have two machines that should be identical but on one system there are some oracle environment (ORACLE_SID, ORACLE_HOME, etc...) variables that are not being set for the users. I am trying to find where those environment variables are being set on the system which is working properly. All...

## Finding the most frequently occurring set of words

Hi guys, I have a file with a list of phoneme for words, it looks like this: AILS EY1 L Z AIMLESSLY EY1 M L AH0 S L IY0 AIMONE EY1 M OW2 N AIMS EY1 M Z AINGE EY1 NG AINGE(2) EY1 N JH AINLEY EY1 N L IY0 AINSLIE EY1 N Z L IY0 AIR EH1 R AIRBAGS EH1 R B AE2 G Z and I need to...

## PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All, I'm writing a nagios check that will see if our ldap servers are in sync... I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable so...eg...let take the single array...

## Finding register set being used in program

How can i find( or list) contents of all registers being used by my program? Is there any system call or library available for this?:confused: At runtime in my c/c++ program. At runtime using may be some assembly hack!!!!!!!!!!!

## Finding Max value from an array

Hi, I need to find max and second max element from an array. array contains 0338,0337,0339,0340,0401,0402,0403

## Max amount of awk array indices

Does anyone know what the max amount of indices you can store in a awk array?