Asc files and Matlab: How to read the coordinates - matlab
I'm very new to matlab and am more of an ArcGIS user but I'd like to know how I can read asc files into Matlab and read coordinates.
The asc file is as follows (sorry it is huge!)
ncols 32
nrows 32
xllcenter -58.75
yllcenter -38.75
cellsize 2.5
NODATA_value -999
0.00 0.62 0.60 0.38 1.22
0.52 1.09 0.76 0.00 0.94
0.37 0.52 0.71 0.71 1.38
0.13 0.00 0.00 0.00 1.46
0.00 0.00 0.97 0.00 0.41
0.00 0.00 0.41 0.83 0.00
0.00 0.19 0.32 0.00 0.00
0.00 0.86 0.00 0.52 1.34
0.00 1.29 0.00 0.00 1.40
0.83 0.00 0.00 0.00 0.00
0.00 0.00 1.09 0.20 0.00
0.43 0.00 0.96 0.78 0.26
0.00 0.70 0.00 0.92 0.29
0.00 1.19 0.00 1.24 0.73
0.00 1.41 0.00 0.97 1.01
0.66 0.00 0.01 0.67 0.67
0.32 0.69 1.41 0.00 0.08
0.92 0.00 0.00 0.40 0.00
0.00 0.00 0.00 1.27 1.24
0.22 0.00 0.00 0.76 0.86
0.00 0.05 0.67 0.29 0.00
0.00 0.04 0.00 0.00 1.18
0.46 0.20 0.00 0.81 0.00
0.00 0.00 1.35 0.40 1.03
0.94 0.90 0.80 0.26 0.73
0.69 0.36 0.70 0.00 0.00
0.42 1.23 0.00 1.24 0.52
0.00 0.54 1.39 1.44 0.00
1.18 0.10 0.00 0.00 0.78
1.33 0.58 0.00 0.00 0.00
0.00 0.92 0.00 0.00 0.00
1.03 0.00 0.00 0.00 0.00
0.66 0.92 0.73 0.00 0.99
0.00 0.00 1.39 0.49 0.97
0.00 1.29 0.00 1.41 1.06
0.00 1.00 0.00 0.00 0.00
0.00 0.32 0.69 1.26 0.00
0.00 0.71 0.00 1.08 1.16
0.00 0.00 0.48 0.00 1.17
0.24 0.00 0.00 0.41 0.00
1.24 1.30 0.00 0.00 0.00
0.00 1.23 0.00 0.15 0.00
0.00 0.19 0.00 0.00 1.17
1.41 0.00 0.15 0.48 0.20
1.29 0.00 0.22 0.55 0.00
0.00 0.81 0.00 0.00 0.00
0.00 1.18 1.18 0.00 0.75
1.05 1.18 1.35 0.00 0.82
0.00 0.00 0.25 0.52 0.00
0.00 1.27 1.46 0.00 1.24
0.00 1.03 1.21 0.81 0.00
0.57 0.00 0.00 0.00 0.00
1.06 0.00 1.29 0.70 0.00
0.00 1.01 0.00 0.00 0.00
0.21 0.95 0.00 0.00 0.00
1.23 1.08 0.00 0.00 0.00
0.11 0.00 0.00 0.00 0.00
0.00 0.00 0.76 0.00 0.68
0.10 0.64 0.00 0.72 0.00
1.34 0.53 0.00 0.18 0.00
0.00 0.25 0.22 0.00 0.00
0.00 0.67 0.37 0.00 0.08
0.02 0.00 0.00 0.94 0.52
0.83 0.64 0.00 0.93 1.40
1.03 0.50 0.00 1.20 0.00
0.68 0.00 0.00 1.15 1.20
0.00 0.00 0.00 0.93 0.00
1.25 0.94 1.37 0.00 0.00
0.00 0.77 0.00 1.15 0.66
0.00 1.45 0.00 1.48 0.00
0.36 0.00 0.34 0.00 0.00
1.22 0.74 0.00 0.00 1.17
0.00 0.59 0.00 0.00 1.18
1.32 1.31 1.21 0.45 1.06
0.00 0.18 0.21 0.79 0.47
0.00 0.47 0.00 0.53 0.76
0.00 0.92 0.00 0.00 1.23
1.45 0.00 0.00 0.00 0.00
1.02 0.00 0.00 0.46 0.00
0.00 0.00 0.00 0.38 1.25
0.00 1.25 0.00 0.42 0.17
0.00 0.97 0.20 0.00 0.00
0.31 0.20 0.00 0.00 0.00
0.00 0.70 0.66 0.00 1.15
0.00 0.00 0.91 1.10 0.00
0.12 0.73 0.00 0.19 0.00
1.01 0.00 0.44 0.00 0.21
0.00 0.00 0.00 0.00 0.91
0.01 0.00 1.28 0.00 0.00
0.00 0.16 0.50 0.00 0.00
1.50 0.10 0.00 0.00 0.00
0.07 0.07 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.88
0.00 0.43 0.00 0.00 0.00
0.00 1.23 0.00 1.41 0.33
0.00 0.74 0.00 0.00 0.00
0.74 0.76 0.15 1.07 0.00
0.00 0.00 0.00 1.34 1.20
0.00 0.00 0.00 0.00 0.43
0.22 0.00 1.02 0.99 0.80
0.91 0.75 0.02 0.00 0.18
0.25 0.00 0.52 0.60 0.00
1.11 0.43 0.00 0.00 0.83
1.02 0.76 0.20 0.00 1.24
0.00 0.00 0.00 1.21 0.00
0.00 0.00 0.00 0.00 0.25
0.00 0.00 0.00 0.00 0.87
0.00 0.00 0.00 1.47 1.22
0.86 0.00 0.96 0.60 0.70
0.38 0.09 0.85 1.18 0.49
0.03 0.00 0.00 1.23 0.00
0.00 0.00 0.00 1.06 0.00
1.01 1.39 1.01 0.00 0.00
0.00 0.00 0.00 0.00 1.31
0.00 0.75 0.00 1.22 0.81
1.07 0.00 0.00 0.00 1.12
1.05 0.70 0.13 0.64 1.30
0.00 0.00 0.53 0.47 0.03
0.00 0.00 0.10 1.38 1.32
0.00 1.25 0.00 0.91 0.67
0.00 0.00 0.00 0.00 0.00
1.00 1.14 0.00 0.00 0.52
0.00 0.02 0.15 0.01 0.90
0.00 0.00 0.70 0.00 0.00
0.00 0.00 0.00 0.00 0.00
0.12 0.72 0.00 0.00 0.04
0.01 0.00 0.00 1.11 1.43
0.91 0.34 0.97 0.00 0.07
0.00 0.00 0.00 0.00 0.93
0.00 0.93 0.00 0.00 0.00
0.93 0.00 0.88 0.29 0.00
0.00 1.50 0.00 0.05 0.00
0.00 0.00 0.00 0.76 1.26
0.00 0.43 0.55 0.40 0.28
0.00 0.07 0.51 0.51 0.00
0.76 0.00 0.00 0.41 0.10
1.16 0.07 0.00 0.00 0.65
0.00 0.21 0.00 0.00 1.41
0.00 1.31 0.19 1.44 0.00
0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.94 0.00
1.12 0.68 0.00 0.00 0.81
0.00 0.00 0.00 0.96 0.00
0.38 0.00 0.00 0.46 0.00
1.15 0.36 0.70 1.04 0.89
1.47 1.20 0.00 0.35 0.00
0.49 0.00 0.00 1.48 0.00
0.00 0.45 1.42 0.00 1.12
0.00 0.00 1.20 1.27 0.00
0.00 0.68 0.30 0.00 0.00
1.20 0.00 0.89 0.00 0.00
0.00 0.00 0.00 0.00 0.00
0.00 1.10 0.48 1.48 0.00
1.23 0.00 1.05 0.56 0.86
0.00 0.00 0.15 0.00 0.03
0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.03 0.90 0.00
0.00 0.00 1.10 0.11 0.68
0.07 0.00 0.78 1.28 1.06
0.39 0.46 0.26 0.00 0.00
0.00 0.85 0.00 0.81 0.00
0.04 0.86 0.00 0.00 0.00
0.00 0.00 0.00 1.45 0.00
0.00 0.00 0.15 0.00 0.00
0.50 0.60 0.00 1.33 0.00
1.15 0.00 1.44 0.82 0.00
0.00 0.01 0.65 0.30 0.00
0.03 0.76 1.12 0.00 0.00
0.59 0.00 0.14 1.16 0.75
0.00 0.00 0.00 0.00 0.00
0.00 1.24 0.41 0.54 1.36
0.00 0.06 0.00 0.00 0.00
0.00 0.76 0.18 1.00 0.00
0.00 0.00 0.00 1.08 0.00
0.00 0.34 0.00 0.82 0.00
0.54 0.00 0.55 0.00 0.97
1.29 0.22 0.00 0.07 0.00
1.31 1.43 0.00 0.35 1.37
0.81 0.00 0.25 0.00 0.90
0.57 0.58 0.00 0.47 0.00
0.51 0.00 0.00 0.50 0.00
0.00 0.00 0.00 1.21 0.23
0.00 0.00 0.00 0.11 0.00
1.08 1.04 0.72 0.00 0.00
0.00 0.00 0.15 0.00 0.80
0.00 0.60 0.00 0.00 1.02
0.00 1.27 0.38 0.69 0.00
1.23 0.00 0.68 0.00 0.31
0.00 0.95 0.00 0.09 0.00
0.00 0.28 0.00 0.00 0.45
0.67 0.92 0.53 1.28 0.13
0.00 0.00 1.02 0.51 0.00
0.00 0.18 0.00 0.00 0.00
0.00 0.00 0.31 0.00 0.98
0.00 0.00 0.00 1.15 0.89
0.00 0.00 0.00 0.42 0.00
1.31 1.27 0.00 0.00 0.00
0.00 0.00 1.23 1.13 0.00
1.05 0.00 0.38 0.00 0.00
0.02 0.00 0.14 0.33 0.12
0.00 0.00 0.00 0.00 0.00
0.00 0.00 1.35 0.18 0.03
0.00 0.00 0.44 0.00 0.00
0.00 1.31 0.19 0.78 0.00
1.17 0.03 1.00 1.02 0.72
nrows and ncols are the number of rows/columns
xllcenter and yllcenter are the coordinates of the centre of the square in the bottom left hand corner of the grid
the cell size is the length of one side of a grid square.
I can read the matrix in and choose to print out values according to their position in the matrix but how would I assign coordinates to such a matrix?
Can I then ask matlab to output the appropriate matrix values when I put in coordinates?
Thanks everyone who can offer me advice!
Since you are a beginner with Matlab, I suggest you investigate the menu option File | Import Data and then study the documentation of the uiimport function.
Related
wondering if sed or awk can reorder using line number [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question I currently have a text file that starts like this, ATOM 277 N DOPC 3 2.637 5.546 17.667 1.00 0.00 MEMB ATOM 278 C12 DOPC 3 2.869 5.398 19.176 1.00 0.00 MEMB ATOM 279 H12A DOPC 3 3.729 6.005 19.418 1.00 0.00 MEMB ATOM 280 H12B DOPC 3 3.176 4.394 19.427 1.00 0.00 MEMB ATOM 281 C13 DOPC 3 1.352 4.873 17.275 1.00 0.00 MEMB ATOM 282 H13A DOPC 3 1.380 5.091 16.217 1.00 0.00 MEMB ATOM 283 H13B DOPC 3 1.415 3.810 17.452 1.00 0.00 MEMB ATOM 284 H13C DOPC 3 0.491 5.261 17.799 1.00 0.00 MEMB ATOM 285 C14 DOPC 3 3.791 4.845 16.976 1.00 0.00 MEMB ATOM 286 H14A DOPC 3 4.692 4.989 17.554 1.00 0.00 MEMB ATOM 287 H14B DOPC 3 3.563 3.790 17.025 1.00 0.00 MEMB ATOM 288 H14C DOPC 3 3.875 5.097 15.930 1.00 0.00 MEMB ATOM 289 C15 DOPC 3 2.627 6.991 17.324 1.00 0.00 MEMB ATOM 290 H15A DOPC 3 1.812 7.530 17.785 1.00 0.00 MEMB . . I'm wondering if there is any way using sed or awk to reorder the lines so that the ordering goes from [1,2,3...14...] to [1,2,5,9,13,3,4,6,7,8,10,11,12,14...] just by simply using their unique line number? Here is the desired output, ATOM 277 N DOPC 3 2.637 5.546 17.667 1.00 0.00 MEMB ATOM 278 C12 DOPC 3 2.869 5.398 19.176 1.00 0.00 MEMB ATOM 281 C13 DOPC 3 1.352 4.873 17.275 1.00 0.00 MEMB ATOM 285 C14 DOPC 3 3.791 4.845 16.976 1.00 0.00 MEMB ATOM 289 C15 DOPC 3 2.627 6.991 17.324 1.00 0.00 MEMB ATOM 279 H12A DOPC 3 3.729 6.005 19.418 1.00 0.00 MEMB ATOM 280 H12B DOPC 3 3.176 4.394 19.427 1.00 0.00 MEMB ATOM 284 H13C DOPC 3 0.491 5.261 17.799 1.00 0.00 MEMB ATOM 286 H14A DOPC 3 4.692 4.989 17.554 1.00 0.00 MEMB ATOM 287 H14B DOPC 3 3.563 3.790 17.025 1.00 0.00 MEMB ATOM 288 H14C DOPC 3 3.875 5.097 15.930 1.00 0.00 MEMB ATOM 290 H15A DOPC 3 1.812 7.530 17.785 1.00 0.00 MEMB . . Thanks!
In awk: $ awk -v order="1,2,5,9,13,3,4,6,7,8,10,11,12,13,14" '{ a[NR]=$0 # hash records to a with NR as index } END { n=split(order,o,/,/) # split the given order to a mapping for(i=1;i<=n;i++) { # iterate the map indexes print a[o[i]] # output # delete a[o[i]] # uncomment these } # for(i=1;i<=NR;i++) # to print any leftovers # if(i in a) # that were not in the order list # print a[i] }' file
Use this Perl one-liner: perl -ne 'push #a, $_; END { print $a[$_-1] for ( 1,2,5,9,13,3,4,6,7,8,10,11,12,13,14, 15..($#a+1) ); }' in_file > out_file The Perl one-liner uses these command line flags: -e : Tells Perl to look for code in-line, instead of in a file. -n : Loop over the input one line at a time, assigning it to $_ by default. push #a, $_; : Add to the array #a (which is empty initially) the current line as the next element. $#a : The index of the last element of the array #a. END { ... } : After all input lines have been read, execute the code inside the block. Here, print the lines in the specified order.
Need to add a column in cross tab report
This is my cross-tab crystal report for sales per week. In last column I need the "Change" column at last in which ((21-Jun's value - 14-Jun's value)/14-Jun's value)*100 will be shown. But I am not be able to achieve that in crystal report. **Product Customer 31-May 7-Jun 14-Jun 21-Jun** J.B. Officeprint 1111 Maxi-Teq 4.00 1.00 1.00 1.00 Microchips 1.00 1.00 0.00 0.00 Parameter 2.00 1.00 0.00 0.00 Total 7.00 3.00 1.00 1.00 J.B. Officeprint 1420 Maxi-Teq 4.00 1.00 1.00 1.00 Microchips 1.00 1.00 0.00 1.00 Parameter 2.00 1.00 0.00 1.00 Total 7.00 3.00 1.00 3.00 Motherboard BTX Maxi-Teq 1.00 0.00 0.00 0.00 Total 1.00 0.00 0.00 0.00 Motherboard MicroATX Maxi-Teq 1.00 0.00 0.00 0.00 Total 1.00 0.00 0.00 0.00 Printer Paper A4 Parameter 0.00 0.00 1.00 0.00 Total 0.00 0.00 1.00 0.00 Printer Paper A4 White Maxi-Teq 0.00 0.00 0.00 12.00 Microchips 0.00 0.00 30.00 0.00 Parameter 0.00 0.00 6.00 0.00 Total 0.00 0.00 36.00 12.00 Grand Total 16.00 6.00 39.00 16.00
you can do it using calculated member. go to the preview and right click on 21-June column and go to calculated member and insert column Edit.................................................................. Go to edit calculation formula and write your code.
zend_cache:I have 506790 cache files,is the cause of high IO on read reason?
Recently I needed to speed up a legacy project(use zend framework 1.10.2),that project use zend_cache,I am new in zend framework. the default.ini configure: data.cache.interim.frontend.name = "Core" data.cache.interim.frontend.options.lifetime = 311040000 ; 10 years data.cache.interim.backend.name = "File" data.cache.interim.backend.options.cache_dir = "/cache/dp-interim/" data.cache.interim.backend.options.hashed_directory_level = 3 There have 506790 cache files in /cache/dp-interim (run command: ls -lR | grep "^-" | wc -l on /cache/dp-interim get the result). run "iotop",get the result: TOTAL DISK READ : 1034.22K/s run "iostat",the result: avg-cpu: %user %nice %system %iowait %steal %idle 1.80 0.00 0.77 51.80 0.00 45.62 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util xvdap1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdb 48.00 0.00 245.00 0.00 2344.00 0.00 9.57 1.51 6.16 3.95 96.80 xvdap3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdf 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 avg-cpu: %user %nice %system %iowait %steal %idle 2.05 0.00 1.03 45.90 0.00 51.03 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util xvdap1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdb 43.00 0.00 214.00 0.00 2056.00 0.00 9.61 1.10 5.20 4.47 95.60 xvdap3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdf 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 avg-cpu: %user %nice %system %iowait %steal %idle 2.06 0.00 0.26 46.91 0.00 50.77 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util xvdap1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdb 62.00 0.00 196.00 0.00 2064.00 0.00 10.53 1.64 8.33 5.06 99.20 xvdap3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdf 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 qavg-cpu: %user %nice %system %iowait %steal %idle 2.33 0.00 2.59 45.34 0.00 49.74 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util xvdap1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdb 33.00 0.00 331.00 0.00 2912.00 0.00 8.80 0.99 3.01 2.68 88.80 xvdap3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 xvdf 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 It is the larger cache file cause the IO height? Thanks for you help!
Matlab: sum for two time series dataset?
I like to sum up the observations of two time series datasets when both of them have observations based on YEAR and DOY. I also like to skip the sum when either dataset has 0 and only do the sum for the maximum observation in that DOY. Here is the example: data_1 and data_2. data_1 % YEAR DOY OBS_1 1994 109 0.42 1994 110 0.73 1994 111 0.69 1994 113 0.8 1994 114 0.43 1994 115 0.75 1994 123 0.6 1994 127 0.2 1994 131 0.44 1994 131 0.43 1994 131 0.63 1994 132 0.99 1994 132 0.51 1994 133 0.71 1994 133 0.99 1994 134 0.65 1994 134 0.69 1994 134 0.97 1994 134 0.03 1994 134 0 1994 134 0 1994 135 0.68 1994 135 0.72 1994 136 1.22 1994 136 0 1994 136 0 1994 136 1.28 1994 136 1.34 data_2: % YEAR DOY OBS_2 1994 110 0.92 1994 111 0.34 1994 113 0.42 1994 114 0.37 1994 115 0.38 1994 122 0.22 1994 127 0.32 1994 131 0.34 1994 131 0.2 1994 132 0.51 1994 132 0.43 1994 132 0.4 1994 133 0.4 1994 134 0.32 1994 134 0.39 1994 135 0.35 1994 135 0.38 1994 135 0.34 1994 135 1.83 1994 135 0.22 1994 135 0.36 1994 135 0.39 1994 135 0.24 1994 135 0.39 1994 136 0.42 1994 136 0.29 1994 136 0.3 1994 136 0.4 1994 136 0.54 1994 136 0.4
Here is a first attempt: %# maximum day of year sz = max(max(data_1(:,2)),max(data_2(:,2))); doy = (1:sz)'; %# get max value for each DOY in each dataset v1 = accumarray(data_1(:,2), data_1(:,3), [sz 1], #max); v2 = accumarray(data_2(:,2), data_2(:,3), [sz 1], #max); %# compute the sum v = v1 + v2; %# keep entries where none of the values were zeros idx = (v1~=0 & v2~=0); v = [doy(idx(:)) v(idx(:))]; The result: >> v v = 110 1.65 111 1.03 113 1.22 114 0.8 115 1.13 127 0.52 131 0.97 132 1.5 133 1.39 134 1.36 135 2.55 136 1.88 I didn't take the year field into account, since its 1994 across all your data...
Deleting all characters except selected one
I have lines as this ATOM 21001 O WAT 345 7.556 35.954 37.464 0.00 0.00 ATOM 21002 H1 WAT 345 7.076 35.701 36.675 0.00 0.00 ATOM 21003 H2 WAT 345 7.155 35.440 38.164 0.00 0.00 TER 0 0 0.000 0.000 0.000 0.00 0.00 ATOM 21004 O WAT 346 1.183 42.629 26.928 0.00 0.00 ATOM 21005 H1 WAT 346 1.412 43.325 26.313 0.00 0.00 ATOM 21006 H2 WAT 346 1.454 41.823 26.490 0.00 0.00 TER 0 0 0.000 0.000 0.000 0.00 0.00 ATOM 21007 O WAT 347 7.166 53.716 22.860 0.00 0.00 ATOM 21008 H1 WAT 347 7.950 54.234 22.675 0.00 0.00 ATOM 21009 H2 WAT 347 6.855 54.045 23.704 0.00 0.00 TER 0 0 0.000 0.000 0.000 0.00 0.00 ATOM 21010 O WAT 348 9.342 45.695 11.193 0.00 0.00 ATOM 21011 H1 WAT 348 8.488 45.846 10.788 0.00 0.00 ATOM 21012 H2 WAT 348 9.973 45.870 10.494 0.00 0.00 TER 0 0 0.000 0.000 0.000 0.00 0.00 ATOM 21013 O WAT 349 18.303 47.277 18.814 0.00 0.00 ATOM 21014 H1 WAT 349 17.411 47.357 18.476 0.00 0.00 ATOM 21015 H2 WAT 349 18.862 47.407 18.047 0.00 0.00 I want to delete all the characters in line contains TER except the TER word. I have searched Internet for sed command which can do this but i can not find one which matching specific word. Could anyone help?
You need to use the following: sed 's/^TER.*$/TER/'