Applying filters


 
Thread Tools Search this Thread
Top Forums Programming Applying filters
# 1  
Old 02-08-2011
Creating array with values around a value X

I have a value X, a value DX and an odd integer N (say N=9) and want to create an array such that
Code:
let X = 10, DX = 2 and N = 9

DIST(1) = X - 4 * DX
DIST(2) = X - 3 * DX
DIST(3) = X - 2 * DX
DIST(4) = X - DX
DIST(5) = X
DIST(6) = X + DX
DIST(7) = X + 2 * DX
DIST(8) = X + 3 * DX
DIST(9) = X + 4 * DX

How can I do a loop to do this?

Moderator's Comments:
Mod Comment Please start using code tags.

Last edited by Scott; 02-08-2011 at 02:19 PM..
# 2  
Old 02-08-2011
It should looks like:
Code:
for( i=-4; i<=4; i++ ) {
  DIST[i+5] = X + i * DX
}

# 3  
Old 02-08-2011
Notice how the values of DIST(i) can be assigned alternatively -

Code:
DIST(1) = X - 4 * DX     = X + (-5 + 1) * DX
DIST(2) = X - 3 * DX     = X + (-5 + 2) * DX
DIST(3) = X - 2 * DX     = X + (-5 + 3) * DX
DIST(4) = X - DX         = X + (-5 + 4) * DX
DIST(5) = X              = X + (-5 + 5) * DX
DIST(6) = X + DX         = X + (-5 + 6) * DX
DIST(7) = X + 2 * DX     = X + (-5 + 7) * DX
DIST(8) = X + 3 * DX     = X + (-5 + 8) * DX
DIST(9) = X + 4 * DX     = X + (-5 + 9) * DX

Quote:
Originally Posted by kristinu
I have a value X, a value DX and an odd integer N (say N=9) and want to create an array such that
Code:
let X = 10, DX = 2 and N = 9
...

How can I do a loop to do this?
...
Assuming you want to use X, DX, N and DIST in your loop construct, you could do something like this -

Code:
for( i = 1; i <= N; i++ )
{
  DIST[i] = X + (-5 + i) * DX
}

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Applying awk

I have a file that is formatted like this: ======== aaaa 11111 bbbb 2222 cccc 3333 ============ dddd 4444 eeee 5555 ffff 6666 ============ trying to get the file to look like this: ====== aaaa aaaa 1111 aaaa bbbb 2222 aaaa cccc 3333 ============= dddd dddd 4444 dddd... (2 Replies)
Discussion started by: jimmyf
2 Replies

2. Shell Programming and Scripting

Need help in filters

Hi, I have input data. 9214919702; B5; 1;20070216; 9231590437; BY; 1;20070215;9;20091022;12;20091022; 9211765888; AZ; 1;20080802;1;20080802;14;20091027; 9231592590; BY; 1;20070215;9;20091026;9;20091026; 9252412219; MM; 1;20070217; 9214917135; MM; 1;20070215; 9214917056; B5; 1;20070215;... (8 Replies)
Discussion started by: suresh3566
8 Replies

3. UNIX for Advanced & Expert Users

Unix- filters ppt

Hello.. i want a ppt on unix filters.. can anybody gv me d link 4 that?? (1 Reply)
Discussion started by: shweta_babbar
1 Replies

4. UNIX for Dummies Questions & Answers

Difference between filters of ps

Hi I am a newbie to Unix . I am just trying to understand the difference between various filters for ps. Can someoen pelase explain me whta is the difference between using /usr/bin/ps -ef | grep <PID> or <Process name> and /usr/bin/ps -auxwww| grep <PID> or <Process Name>. (1 Reply)
Discussion started by: sillybirdie123
1 Replies

5. UNIX for Dummies Questions & Answers

filters

how to filter one particular row from one text file and copy it in another? (1 Reply)
Discussion started by: rajanandhini
1 Replies

6. UNIX for Dummies Questions & Answers

How can I use filters to extract infos?

I encountered some complicated problems course studies. take this for example: under /home/data/stockdata we have 1999,2000,2001,.......2004 these sub-dirs and, each sub-dir has its mothly(for Jan~Dec) transaction records, i.e. they are all named "foo.txt", like this: Date ... (2 Replies)
Discussion started by: virii
2 Replies

7. Solaris

Solaris lp printer filters

I don't have much experience with solaris printers. I've created a printer using lpadmin. When I tried to print something, I got a message that there a no filters on the server. I went to docs.sun.com and got a script to add a filter (below) for filter in *.fd;do >name=`basename $filter... (1 Reply)
Discussion started by: soliberus
1 Replies

8. UNIX for Dummies Questions & Answers

IP Filters

Anyone know where I can find good documentation for IPF on the Internet? Thanks, Chuck (1 Reply)
Discussion started by: 98_1LE
1 Replies
Login or Register to Ask a Question