Delete specific lines from a file based on another file - sed

I have some text files in a folder named ff as follows. I need to delete the lines in these files based on another file aa.txt.
32bm.txt:
249 253 A P - 0 0 8 0, 0.0 6,-1.4 0, 0.0 2,-0.4 -0.287 25.6-102.0 -74.4 161.1 37.1 13.3 10.9
250 254 A K B Z 254 0E 77 -48,-2.5 -48,-0.3 4,-0.2 4,-0.3 -0.720 360.0 360.0 -93.4 135.2 38.1 11.1 8.1
252 !* 0 0 0 0, 0.0 0, 0.0 0, 0.0 0, 0.0 0.000 360.0 360.0 360.0 360.0 0.0 0.0 0.0
253 143 B R 0 0 96 0, 0.0 -2,-3.7 0, 0.0 2,-0.2 0.000 360.0 360.0 360.0 110.4 38.4 10.4 3.0
254 144 B Q B -Z 250 0E 62 -4,-0.3 -4,-0.2 -3,-0.1 2,-0.1 -0.347 360.0-157.5 -58.1 119.5 39.4 13.6 4.8
255 145 B T - 0 0 22 -6,-1.4 2,-0.3 -2,-0.2 -7,-0.2 -0.396 7.8-127.4 -91.5 173.9 36.3 15.7 5.4
2fok.txt:
1 361 X G 0 0 137 0, 0.0 2,-0.2 0, 0.0 3,-0.0 0.000 360.0 360.0 360.0 97.3 25.2 -16.6 -6.6
2 362 X A - 0 0 98 1,-0.0 0, 0.0 0, 0.0 0, 0.0 -0.649 360.0 -33.9-148.3 84.1 28.0 -18.6 -4.8
3 363 X R - 0 0 226 -2,-0.2 2,-0.0 1,-0.1 -1,-0.0 1.000 68.7-149.8 66.4 76.9 31.1 -16.5 -4.0
1 361 B G 0 0 137 0, 0.0 2,-0.2 0, 0.0 3,-0.0 0.000 360.0 360.0 360.0 97.3 25.2 -16.6 -6.6
2 362 B A - 0 0 98 1,-0.0 0, 0.0 0, 0.0 0, 0.0 -0.649 360.0 -33.9-148.3 84.1 28.0 -18.6 -4.8
3 363 B R - 0 0 226 -2,-0.2 2,-0.0 1,-0.1 -1,-0.0 1.000 68.7-149.8 66.4 76.9 31.1 -16.5 -4.0`enter code here`
aa.txt:
32bm B 143 145
2fok X 361 363
2moj B 361 367
-
-
-
For example, in the 32bm.txt, I need only the lines having B (column3) and the numbers from 143 to 145 (column2).
Desired output:
32bm.txt
253 143 B R 0 0 96 0, 0.0 -2,-3.7 0, 0.0 2,-0.2 0.000 360.0 360.0 360.0 110.4 38.4 10.4 3.0
254 144 B Q B -Z 250 0E 62 -4,-0.3 -4,-0.2 -3,-0.1 2,-0.1 -0.347 360.0-157.5 -58.1 119.5 39.4 13.6 4.8
255 145 B T - 0 0 22 -6,-1.4 2,-0.3 -2,-0.2 -7,-0.2 -0.396 7.8-127.4 -91.5 173.9 36.3 15.7 5.4
2fok.txt
1 361 X G 0 0 137 0, 0.0 2,-0.2 0, 0.0 3,-0.0 0.000 360.0 360.0 360.0 97.3 25.2 -16.6 -6.6
2 362 X A - 0 0 98 1,-0.0 0, 0.0 0, 0.0 0, 0.0 -0.649 360.0 -33.9-148.3 84.1 28.0 -18.6 -4.8
3 363 X R - 0 0 226 -2,-0.2 2,-0.0 1,-0.1 -1,-0.0 1.000 68.7-149.8 66.4 76.9 31.1 -16.5 -4.0

With awk you do something like this:
#!/usr/bin/awk -f
NR == FNR { # If we are in the first file
low[$1,$2]=$3 # store the low value in a map
hi[$1,$2]=$4 # store the high value in another map
next # skip the remaining commands
}
# We are not in the first file
($2 >= low[FILENAME,$3]) && ($2 <= hi[FILENAME,$3])
# The FILENAME variable holds the name of the current file
# If the number we read is within the range, do the
# default action (which is to print the current line
put the script in a file named script.awk and run like this:
$ ./script.awk aa.txt 32bm 2fok
253 143 B R 0 0 96 0, 0.0 -2,-3.7 0, 0.0 2,-0.2 0.000 360.0 360.0 360.0 110.4 38.4 10.4 3.0
254 144 B Q B -Z 250 0E 62 -4,-0.3 -4,-0.2 -3,-0.1 2,-0.1 -0.347 360.0-157.5 -58.1 119.5 39.4 13.6 4.8
255 145 B T - 0 0 22 -6,-1.4 2,-0.3 -2,-0.2 -7,-0.2 -0.396 7.8-127.4 -91.5 173.9 36.3 15.7 5.4
1 361 X G 0 0 137 0, 0.0 2,-0.2 0, 0.0 3,-0.0 0.000 360.0 360.0 360.0 97.3 25.2 -16.6 -6.6
2 362 X A - 0 0 98 1,-0.0 0, 0.0 0, 0.0 0, 0.0 -0.649 360.0 -33.9-148.3 84.1 28.0 -18.6 -4.8
3 363 X R - 0 0 226 -2,-0.2 2,-0.0 1,-0.1 -1,-0.0 1.000 68.7-149.8 66.4 76.9 31.1 -16.5 -4.0
Or if you prefer a one liner:
awk 'NR==FNR{low[$1,$2]=$3;hi[$1,$2]=$4;next}$2>=low[FILENAME,$3]&&$2<=hi[FILENAME,$3]' aa.txt 32bm 2fok

Related

select-string works on get-content but not directly on invoke-webclient content

A part of an automated tool chain needs some input data from a website accessible through a well-documented and working API to fetch data in "CSV" format. The output of the Invoke-WebRequest requires some further selection of the response data, since the response not only contains the desired "CSV" data but also some explanatory lines. Here's the data (exact URL to reproduce below):
Latitude (deg.): 51.654
Longitude (deg.): 6.606
A H_hor A_sun(w) H_sun(w) A_sun(s) H_sun(s)
-180.0 0.8 -180.0 0.0 -180.0 0.0
-172.5 0.8 -165.6 0.0 -172.9 0.0
-165.0 1.1 -152.1 0.0 -165.9 0.0
-157.5 1.1 -140.0 0.0 -158.9 0.0
-150.0 1.1 -129.4 0.0 -152.2 0.0
-142.5 1.5 -120.1 0.0 -145.7 0.0
-135.0 1.5 -112.0 0.0 -139.4 0.0
-127.5 1.5 -104.7 0.0 -133.3 0.0
-120.0 1.5 -98.1 0.0 -127.4 1.6
-112.5 1.5 -91.9 0.0 -121.6 5.4
-105.0 1.5 -86.1 0.0 -116.0 9.5
-97.5 1.5 -80.5 0.0 -110.5 13.8
-90.0 1.5 -74.9 0.0 -105.1 18.2
-82.5 1.5 -69.5 0.0 -99.5 22.7
-75.0 1.5 -64.0 0.0 -93.9 27.3
-67.5 1.1 -58.4 0.0 -88.1 32.0
-60.0 1.1 -52.6 0.0 -81.9 36.6
-52.5 1.1 -46.7 2.0 -75.3 41.2
-45.0 1.1 -40.6 5.2 -68.0 45.6
-37.5 1.1 -34.3 8.0 -59.9 49.8
-30.0 0.0 -27.8 10.4 -50.6 53.6
-22.5 0.4 -21.1 12.3 -40.0 56.9
-15.0 0.4 -14.1 13.7 -27.9 59.5
-7.5 0.4 -7.1 14.6 -14.4 61.2
0.0 0.0 0.0 14.9 0.0 61.8
7.5 0.0 7.1 14.6 14.4 61.2
15.0 0.0 14.1 13.7 27.9 59.5
22.5 0.0 21.1 12.3 40.0 56.9
30.0 0.4 27.8 10.4 50.6 53.6
37.5 0.0 34.3 8.0 59.9 49.8
45.0 0.0 40.6 5.2 68.0 45.6
52.5 0.0 46.7 2.0 75.3 41.2
60.0 0.0 52.6 0.0 81.9 36.6
67.5 0.0 58.4 0.0 88.1 32.0
75.0 0.0 64.0 0.0 93.9 27.3
82.5 0.4 69.5 0.0 99.5 22.7
90.0 0.4 74.9 0.0 105.1 18.2
97.5 0.0 80.5 0.0 110.5 13.8
105.0 0.8 86.1 0.0 116.0 9.5
112.5 0.8 91.9 0.0 121.6 5.4
120.0 0.8 98.1 0.0 127.4 1.6
127.5 0.8 104.7 0.0 133.3 0.0
135.0 0.4 112.0 0.0 139.4 0.0
142.5 0.4 120.1 0.0 145.7 0.0
150.0 0.8 129.4 0.0 152.2 0.0
157.5 0.8 140.0 0.0 158.9 0.0
165.0 0.8 152.1 0.0 165.9 0.0
172.5 0.8 165.6 0.0 172.9 0.0
180.0 0.8 180.0 0.0 180.0 0.0
A: Azimuth (0 = S, 90 = W, -90 = E) (degree)
H_hor: Horizon height (degree)
A_sun(w): Sun azimuth in the winter solstice (Dec 21) (0 = S, 90 = W, -90 = E) (degree)
H_sun(w): Sun height in the winter solstice (Dec 21) (degree)
A_sun(s): Sun azimuth in the summer solstice (June 21) (0 = S, 90 = W, -90 = E) (degree)
H_sun(s): Sun height in the summer solstice (June 21) (degree)
PVGIS (c) European Union, 2001-2021
I'd like to only select the lines matching '^[0-9-]' (positive and negative numbers). Essentially, selecting the following lines:
-180.0 0.8 -180.0 0.0 -180.0 0.0
-172.5 0.8 -165.6 0.0 -172.9 0.0
-165.0 1.1 -152.1 0.0 -165.9 0.0
-157.5 1.1 -140.0 0.0 -158.9 0.0
-150.0 1.1 -129.4 0.0 -152.2 0.0
-142.5 1.5 -120.1 0.0 -145.7 0.0
-135.0 1.5 -112.0 0.0 -139.4 0.0
-127.5 1.5 -104.7 0.0 -133.3 0.0
-120.0 1.5 -98.1 0.0 -127.4 1.6
-112.5 1.5 -91.9 0.0 -121.6 5.4
-105.0 1.5 -86.1 0.0 -116.0 9.5
-97.5 1.5 -80.5 0.0 -110.5 13.8
-90.0 1.5 -74.9 0.0 -105.1 18.2
-82.5 1.5 -69.5 0.0 -99.5 22.7
-75.0 1.5 -64.0 0.0 -93.9 27.3
-67.5 1.1 -58.4 0.0 -88.1 32.0
-60.0 1.1 -52.6 0.0 -81.9 36.6
-52.5 1.1 -46.7 2.0 -75.3 41.2
-45.0 1.1 -40.6 5.2 -68.0 45.6
-37.5 1.1 -34.3 8.0 -59.9 49.8
-30.0 0.0 -27.8 10.4 -50.6 53.6
-22.5 0.4 -21.1 12.3 -40.0 56.9
-15.0 0.4 -14.1 13.7 -27.9 59.5
-7.5 0.4 -7.1 14.6 -14.4 61.2
0.0 0.0 0.0 14.9 0.0 61.8
7.5 0.0 7.1 14.6 14.4 61.2
15.0 0.0 14.1 13.7 27.9 59.5
22.5 0.0 21.1 12.3 40.0 56.9
30.0 0.4 27.8 10.4 50.6 53.6
37.5 0.0 34.3 8.0 59.9 49.8
45.0 0.0 40.6 5.2 68.0 45.6
52.5 0.0 46.7 2.0 75.3 41.2
60.0 0.0 52.6 0.0 81.9 36.6
67.5 0.0 58.4 0.0 88.1 32.0
75.0 0.0 64.0 0.0 93.9 27.3
82.5 0.4 69.5 0.0 99.5 22.7
90.0 0.4 74.9 0.0 105.1 18.2
97.5 0.0 80.5 0.0 110.5 13.8
105.0 0.8 86.1 0.0 116.0 9.5
112.5 0.8 91.9 0.0 121.6 5.4
120.0 0.8 98.1 0.0 127.4 1.6
127.5 0.8 104.7 0.0 133.3 0.0
135.0 0.4 112.0 0.0 139.4 0.0
142.5 0.4 120.1 0.0 145.7 0.0
150.0 0.8 129.4 0.0 152.2 0.0
157.5 0.8 140.0 0.0 158.9 0.0
165.0 0.8 152.1 0.0 165.9 0.0
172.5 0.8 165.6 0.0 172.9 0.0
180.0 0.8 180.0 0.0 180.0 0.0
As an example, let's look at the following session explaining my confusion:
~##❯ $horizonUrl = 'https://re.jrc.ec.europa.eu/api/printhorizon?lat=51.654&lon=6.606&browser=0&outputformat=csv'
~##❯ $response = Invoke-WebRequest -Uri $horizonUrl
~##❯ $respcont = $response.Content
~##❯ $respcontstr = [String[]]$response.Content
~##❯ $respcontobj = [Object[]]$response.Content
~##❯ $respcont | Select-String -Pattern "^[0-9-]" -Raw
~##❯ $respcontstr | Select-String -Pattern "^[0-9-]" -Raw
~##❯ $respcontobj | Select-String -Pattern "^[0-9-]" -Raw
~##❯ $respcont.GetType().Name + " " + $respcont.GetType().BaseType
String System.Object
~##❯ $respcontstr.GetType().Name + " " + $respcontstr.GetType().BaseType
String[] array
~##❯ $respcontobj.GetType().Name + " " + $respcontobj.GetType().BaseType
Object[] array
---> No output on the Select-String for the variants above <---
~##❯ Invoke-WebRequest -Uri $horizonUrl -OutFile .\horizon.csv
~##❯ $gc = (Get-Content .\horizon.csv)
~##❯ $gc.GetType().Name + " " + $gc.GetType().BaseType
Object[] array
~##❯ $gc | Select-String -Pattern "^[0-9-]" -Raw
-180.0 0.8 -180.0 0.0 -180.0 0.0
-172.5 0.8 -165.6 0.0 -172.9 0.0
-165.0 1.1 -152.1 0.0 -165.9 0.0
-157.5 1.1 -140.0 0.0 -158.9 0.0
-150.0 1.1 -129.4 0.0 -152.2 0.0
-142.5 1.5 -120.1 0.0 -145.7 0.0
-135.0 1.5 -112.0 0.0 -139.4 0.0
-127.5 1.5 -104.7 0.0 -133.3 0.0
[...]
---> Piped through Get-Content, Select-String dumps the desired output <---
How come Select-String works well together with an intermediate file in piped command chain, however not when used directly, without storing the response content of the Invoke-WebRequest?
The explicit type conversion above was my meager attempt at mimicking the data structure of the output of Get-Content. All the outputs before the pipe look identical in the console (lines of strings).
What did I miss?
The Content property on the response object you get from Invoke-WebRequest is a single multi-line string. Get-Content on the other hand returns multiple single-line strings.
You can use the -split operator to split on newlines:
$respcont -split '\r?\n' |Select -Skip 4 |Select -SkipLast 9

HALog - Connect and response times percentiles

When I run the following command to parse haproxy logs, the output doesn't contain any headers, and I'm not able to understand the meanings of the numbers in each of the columns.
Command halog -pct < haproxy.log > percentiles.txt
the output that I see is:
0.1 3493 18 0 0 0
0.2 6986 25 0 0 0
0.3 10479 30 0 0 0
0.4 13972 33 0 0 0
0.5 17465 37 0 0 0
0.6 20958 40 0 0 0
0.7 24451 43 0 0 0
0.8 27944 46 0 0 0
0.9 31438 48 0 0 0
1.0 34931 49 0 0 0
1.1 38424 50 0 0 0
1.2 41917 51 0 0 0
1.3 45410 52 0 0 0
1.4 48903 53 0 0 0
1.5 52396 55 0 0 0
1.6 55889 56 0 0 0
1.7 59383 57 0 0 0
1.8 62876 58 0 0 0
1.9 66369 60 0 0 0
2.0 69862 61 0 0 0
3.0 104793 74 0 0 0
4.0 139724 80 0 1 0
5.0 174656 89 0 1 0
6.0 209587 94 0 1 0
7.0 244518 100 0 1 0
8.0 279449 106 0 1 0
9.0 314380 112 0 1 0
10.0 349312 118 0 1 0
15.0 523968 144 0 1 0
20.0 698624 168 0 1 0
25.0 873280 180 0 2 0
30.0 1047936 190 0 2 0
35.0 1222592 200 0 3 0
40.0 1397248 210 0 3 0
45.0 1571904 220 0 4 0
50.0 1746560 230 0 6 0
55.0 1921216 241 0 7 0
60.0 2095872 258 0 9 0
65.0 2270528 279 0 10 0
70.0 2445184 309 0 16 0
75.0 2619840 354 1 18 0
80.0 2794496 425 1 20 0
85.0 2969152 545 1 22 0
90.0 3143808 761 1 39 1
91.0 3178740 821 1 80 1
92.0 3213671 921 1 217 1
93.0 3248602 1026 1 457 1
94.0 3283533 1190 1 683 1
95.0 3318464 1408 1 889 1
96.0 3353396 1721 1 1107 1
97.0 3388327 2181 1 1328 1
98.0 3423258 2902 1 1555 1
98.1 3426751 3000 1 1580 1
98.2 3430244 3094 1 1607 1
98.3 3433737 3196 1 1635 1
98.4 3437231 3301 1 1666 1
98.5 3440724 3420 1 1697 1
98.6 3444217 3550 1 1731 1
98.7 3447710 3690 1 1770 1
98.8 3451203 3848 1 1815 1
98.9 3454696 4030 1 1864 1
99.0 3458189 4249 1 1923 2
99.1 3461682 4490 1 1993 2
99.2 3465176 4766 2 2089 2
99.3 3468669 5085 2 2195 2
99.4 3472162 5441 3 2317 97
99.5 3475655 5899 5 2440 365
99.6 3479148 6517 11 2567 817
99.7 3482641 7403 14 2719 1555
99.8 3486134 8785 16 2992 2779
99.9 3489627 11650 997 3421 4931
100.0 3493121 85004 4008 20914 71716
The first column looks to be the percentile, (like P50, P90, P99, etc) but the what are the values in the 2nd, 3rd, 4th, 5th and 6th columns? Also, are they total values (halog reports total times when provided with other options), or average values or maximum values?
<percentile> <request count> <Request Time*> <Connect Time**> <Response Time***> <Data Time****>
* Referred to as TR in the documentation.
** Referred to as Tc in the documentation.
*** Referred to as Tr in the documentation.
**** Referred to as Td in the documentation.
The source provides some good pointers.

Is there a way to only show the first record in a Crystal Report that does not meet a specified condition?

Say I have data formatted as follows in a Crystal Report:
Job: 1
Asm Opr LbrQty
0 10 0.0
0 10 60.0
0 10 60.0
0 20 65.0
0 30 0.0
0 30 20.0
0 30 40.0
Job: 2
Asm Opr LbrQty
0 10 60.0
0 10 60.0
0 10 75.0
0 20 0.0
0 20 165.0
0 30 0.0
0 30 20.0
0 30 40.0
0 40 60.0
1 10 60.0
1 10 60.0
1 10 75.0
1 20 0.0
1 20 165.0
1 30 0.0
1 30 20.0
1 40 0.0
1 40 60.0
I only want the report to show the first Opr within an Asm where LbrQty is NOT zero, as below:
Job: 1
Asm Opr LbrQty
0 10 60.0
0 20 65.0
0 30 20.0
Job: 2
Asm Opr LbrQty
0 10 60.0
0 20 165.0
0 30 20.0
0 40 60.0
1 10 60.0
1 20 165.0
1 30 20.0
1 40 60.0
I've attempted to use the following as my Supression Formula, which works for the most part, but still occasionally displays multiple records with the same Opr:
(
Previous ({OprSeq}) = ({OprSeq}) and
Previous ({JobNum}) = ({JobNum}) and
Previous ({LaborQty}) <> 0
) or
(
({LaborQty}) = 0
)
How can I change my formula to give me the behavior I require?
Try below way:
Create a running total with following criteria:
In field to summairze take lbrqty and take count as summary option
In evalute use option formula and write below code:
{lbrqty}>0
In Reset use option On change of field opr
Now use this running total to supress.. Now in supress of the section write below code:
if {#RTotal1}=1
then false
else true

Netlogo BehaviourSpace weird Output and Multiple Runs

For some weird reason the behaviorSpace in netlogo runs the same value pairs model multiple times even though repetitions are 1. I can't understand why. The output file in table format looks like this. I don't know what's up with double quotes.
BehaviorSpace results (NetLogo 5.2.0)
/home/abhishekb/new_models/basic/try4.nlogo
experiment1
10/26/2015 02:34:28:770 +0530
min-pxcor max-pxcor min-pycor max-pycor
-7 7 -7 7
[run number] knt k threshold scale [step]
16 0 75 0.1 1 2535
7 0 54 0.1 1 0 8715
5 0 47 0.3 1 0 9374
10 0 61 0.1 1 0 8841
"22 0 89 0.1 1 0 3664"8" 0 54 0.3 1 0 12001" 0 40 0.1 1 0 10727
2" 013" 0 68 0.1 1 0"22 0 89 0.1 1 0 4449
128" 0 103 0.1 1 0 2805
4 0 47 0.1 1 0 1200119" 0 82 0.1 1 0 12001"1 0 40 0.1 1 0 12001
3"
26" 0 96 0.3 1 0 4800
9" 0 103 0.3 1 0 43321" 0 82 0.6 1 0 7385
31 0 110 0.1 1 0 2976
1" 0 40 0.1 1 0 12001
4" 0 89 0.6 1 0 6389
25 0 96 0.1 1 0 7517
26 0 96 0.3 1 0 5479
9""27" 0 96 0.6 1 0 6117
28 0 103 0.1 1 0 2219
29 0 103 0.3 1 0 6411
30 0 103 0.6 1 0 5693
31 0 110 0.1 1 0 3985
78 500 61 0.6 1 0 9720
79 500 68 0.1 1 0 6067
80 500 68 0.3 1 0 6795
81 500 68 0.6 1 0 8305
82 500 75 0.1 1 0 4416
83 500 75 0.3 1 0 5742
84 500 75 0.6 1 0 7399
85 500 82 0.1 1 0 5306
86 500 82 0.3 1 0 5388
01"
87 500 82 0.6 1 0 6869
88 500 89 0.1 1 0 12001
89 500 89 0.3 1 0 5097
90 500 89 0.6 1 0 6478
91 500 96 0.1 1 0 2275
92 500 96 0.3 1 0 4693" 500 96 0.6 1 0 6395
94"94 500 103 0.1 1 0 12001
95 500 103 0.3 1 0 3984
96 500 103 0.6 1 0 5440
97 500 110 0.1 1 0 1893
98 500 110 0.3 1 0 37299" 500 110 0.6 1 0 5275
100 750 40 0.1 1 0 12001
101" 750 40 0.3 1 0 12001
102 750 40 0.6 1 0 12001
"
103""" 750 47 0.1 1 0 11911
"
104""" 750 47 0.3 1 0 12001
105 750 47 0.6 1 0 11821
750" 54 0.1 1 0 12001
107 750 54 0.3 1 0 8703
811108" 750 54 0.6 1 0 10099
5"
,61" 0.1 1 0 12001
110 750 61 0.3 1 0 7453
0111" 750111" 750 61 0.6 1 0 9051
112 750 68 0.1 1 0 12001
68 0.3 1 0 12001
BehaviourSpace Code:
##$###$##
NetLogo 5.2.1
##$###$##
##$###$##
##$###$##
<experiments>
<experiment name="experiment1" repetitions="1" runMetricsEveryStep="false">
<setup>check-setup-percent
file-write-values</setup>
<go>go</go>
<final>write-to-file</final>
<timeLimit steps="12000"/>
<exitCondition>count inboxturtles with[exit = 1 and exited = false] = 0</exitCondition>
<steppedValueSet variable="knt" first="0" step="250" last="2500"/>
<steppedValueSet variable="k" first="40" step="7" last="110"/>
<enumeratedValueSet variable="threshold">
<value value="0.1"/>
<value value="0.3"/>
<value value="0.6"/>
</enumeratedValueSet>
<enumeratedValueSet variable="scale">
<value value="1"/>
</enumeratedValueSet>
</experiment>
</experiments>
##$###$##
##$###$##
default
0.0
-0.2 0 0.0 1.0
0.0 1 1.0 0.0
0.2 0 0.0 1.0
link direction
true
0
Line -7500403 true 150 150 90 180
Line -7500403 true 150 150 210 180
##$###$##
1
##$###$##

Set colorbar ranges in 3d graph in matlab

I would like to create a three dimensional surface using this:
>> a=X
a =
Columns 1 through 8
0 50 100 150 200 250 300 350
Columns 9 through 16
400 450 500 550 600 650 700 750
Columns 17 through 21
800 850 900 950 1000
>> b=Y
b =
0
50
100
150
200
250
300
350
400
>> c=Z
c =
Columns 1 through 8
0 0 0 0 0 0 0 0
16 32 67 98 127 164 194 234
120 171 388 773 1086 1216 1770 2206
189 270 494 1978 2755 3134 5060 10469
133 166 183 348 647 937 1446 2304
192 162 154 113 161 189 266 482
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Columns 9 through 16
0 0 0 0 0 0 0 0
366 604 529 504 346 226 228 179
4027 11186 10276 5349 2560 1322 996 799
27413 76387 37949 15591 5804 2654 1803 1069
9844 24152 14772 4613 1777 849 459 290
1288 2623 1538 582 280 148 90 56
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Columns 17 through 21
0 0 0 0 0
108 94 79 0 0
646 476 612 0 0
884 858 722 0 0
266 215 139 0 0
48 48 31 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
>> surf(X,Y,Z)
At the same time I would like to define that Z values < = 1803 will be shown with red color on the surface graph, 1803 < Z < 2755 yellow and Z > = 2755 green. The limits of the colorbar can be the min and max values of Z (from 0 to 76387). How can I set the ranges of the colorbar in order to get this result?
This will do as you ask:
%# add red (row 1), yellow (row 2), green (row 2)
map = [1 0 0; 0 1 1; 0 1 0];
%# set the new map as the current map
colormap(map);
colors = zeros(size(c)); %# create colors array
colors(c <= 1803) = 1; %# red (1)
colors(c > 1803 & c < 2755) = 2; %# yellow (2)
colors(c >= 2755) = 3; %# green (3)
%# and pass it into surf
surf(a,b,c, colors)